Welcome friends to this new blog. In this blog, you will learn how to set up APIs with the help of an express server. You will learn how to integrate graphql in the express server.
GitHub link — https://github.com/nextdev1111/prisma-postgres-graphql-express
Youtube Video in Hindi
📒Notes
I will be using **pnpm for this project but the tutorial will show you how to do it with **npm.
We will be using **typescript **for this project.
Step1: 📦 Setup
Make a folder by whichever name you want but you need to consider npm naming restrictions.
Then run this command
npm init -y
Make another folder named src. Make a file named **index.ts **in the src folder.
[root folder]
--- src
--- --- index.ts
To install dependencies and setup typescript
This will install dependencies 👇
npm i @graphql-tools/schema @prisma/client dotenv express graphql express-graphql
This will install dev dependencies 👇
npm i -D [@types/dotenv](http://twitter.com/types/dotenv) [@types/express](http://twitter.com/types/express) [@types/node](http://twitter.com/types/node) prisma ts-node typescript
Then type 👇 to create a **tsconfig **file.
npm install -g typescript
tsc --init
Step2: 🗃️ Prisma Setup with postgress database
Type this command in your terminal
npm prisma init
Prisma will set up two things in your root folder.
Prisma folder
.env file
In the prisma folder, you can find schema.prisma file.
Let’s add a database now.
go to https://railway.app/
Click on start new project
You can set up a PostgreSQL database. If you find any problem, you can also watch the youtube video.
Then, you should copy the postgresql database connection key
Then go to .env your project’s root folder.
Then change the connection string in your .env file.
→ Remember to also include the password in the connection string.
Then type
prisma db push
⚠️Errors
If you face any errors, you should check the connection string.
Step3: ✨Express Server
This is the basic express server
If you want to add an entry to your database.
You can also use prisma studio
npm prisma studio
Step4: 💪Grahpql Integration
You can use graphiql on this path
[http://localhost:3000/graphql](http://localhost:3000/graphql)
If you want to ask any questions, feel free to ask 👇
Join the Next Dev Discord Server!
Top comments (1)
Some comments may only be visible to logged-in visitors. Sign in to view all comments.