Before starting, make sure you have the following installed:
- Node.js
- NPM or Yarn
- Postgres
- Prisma
- yup
To create prisma files, open a terminal and run the following command:
npm install prisma
npx prisma init
This will install and create all prisma files
In your terminal, navigate to the root directory of your app and run the following command to install Prisma and its dependencies:
npm install prisma @prisma/client dotenv
npm install yup
This will install Prisma, the Prisma client, and dotenv, which we will use to configure our environment variables.
Create a new Postgres database using your preferred method. Once you have created the database, create a new .env file in the root directory of your app and add the following environment variables, replacing the placeholders with your database credentials:
DATABASE_URL=postgresql://<username>:<password>@<hostname>:<port>/<database_name>
Create a new file named schema.prisma in the root directory of your app. In this file, define your database schema using Prisma's schema syntax.
In your terminal, run the following command to generate the Prisma client based on your schema:
npx prisma generate
This will create a new node_modules/@prisma/client directory containing the Prisma client.
add the following environment variables in .env file
PG_USER= your_user
PG_PASSWORD= your_password
PG_HOST= your_host
PG_PORT= your_port_number
PG_DATABASE= your_db_name
Add your existing database Run this command to add existing database
npx prisma db pull
Just copy the all line from terminal after run the step 5 and paste them in starting of your Express App.