How to add Database Layer using Prisma in Node Application

 In this section we will add Database layer like Prisma in our Application so follow below steps.

So Run these command to install Prisma related package.

npm install @prisma/client

iske run karne se package.json me dependencies me ye package aa jata hai.

npm install -D prisma

isko install karne ke baad dev dependencies me package.json me aa jata hai.


@prisma/client runtime client hota hai (app me DB query ke liye)

prisma CLI tool hota hai (schema manage karne aur migrate karne ke liye)

After that we have to initilize prisma by using this command 

npx prisma init

is command se prisma folder me schema.prisma aur main root folder me .env filde ban jayegi.


Express + Prisma, install these common industry-level dependencies:

npm install bcrypt jsonwebtoken express-validator

npm install dotenv cors morgan

Dev dependencies-

npm install -D nodemon

after install nodemon add this script  "dev": "nodemon src/server.js" in package.json script

Now you can use - npm run dev


After that make Schema in schema.prisma and run below command to migrate that schema to database

npx prisma migrate dev --name add-display-names

isase database me schema migrate ho jayega fir schema me data dalne ke liye seeder bana sakte ho backend/prisma/seeder.js like this.



Comments

Popular posts from this blog

Basics Of PHP

Creating App.js for Node Application

WordPress Full Guide For Developer