prisma orm
In the last story, I covered how to setup Prisma. Now we will create Rest APIs using Prisma.
在上一个故事中,我介绍了如何设置Prisma 。 现在,我们将使用Prisma创建Rest API。
要在Node.js中使用Prisma客户端,请先设置Node.js (To use Prisma client in Nodejs, first setup Nodejs)
A. Project setup * npm init -y * npm i body-parser express — save * npm i webpack webpack-cli — save-dev
开始吧 (Let’s start)
Open server.js and create routes to API:
打开server.js并创建到API的路由:
2. Authentication:
2.身份验证:
For authentication first, add the required dependencies to the project:
首先进行身份验证,将所需的依赖项添加到项目中:
npm add lodash bcrypt jsonwebtoken
npm添加lodash bcrypt jsonwebtoken
用途: (Uses:)
3. In API folder create user.js file for creating RESTful API for the user register, a user login, and user delete.
3.在API文件夹中,创建user.js文件,用于为用户注册,用户登录名和用户删除创建RESTful API。
2. In the API folder create file company.js and add the following code.
2.在API文件夹中,创建文件company.js并添加以下代码。
In the API folder, create another file employee.js and write the following code.
在API文件夹中,创建另一个文件employee.js并编写以下代码。
Testing
Ťesting
Run the project by typing the command:
通过键入以下命令运行项目:
npm run start
npm运行开始
Here, You can refer to the previous stories for testing APIs :
在这里,您可以参考先前的故事来测试API:
结论 : (Conclusion:)
We have successfully created Restful APIs using Prisma. 👏
我们已经使用Prisma成功创建了Restful API。 👏
prisma orm