Sitemap

Member-only story

Node.js & Express.js: Build a Simple REST API with CRUD Operations Using Prisma (Javascript)

--

Create a Project Directory and Run This Command to Install Essential Packages

npm init -y
npm i express nodemon dotenv http

Modifications in package.json

{
"name": "nodejs-prisma-example",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"start": "node src/server.js",
"dev": "nodemon src/server.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"@prisma/client": "^6.9.0",
"dotenv": "^16.5.0",
"express": "^5.1.0",
"http": "^0.0.1-security",
"nodemon": "^3.1.10"
},
"devDependencies": {
"prisma": "^6.9.0"
}
}

Now Install Prisma (MySQL)

npm install prisma --save-dev
npx prisma init --datasource-provider mysql --output ../generated/prisma

Generate file .env and prisma/schema.prisma

Change .env according you database configure

DATABASE_URL="mysql://root:password@localhost:3306/nodejs"

Change prisma/schema.prisma File

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
// Try Prisma Accelerate…

--

--

No responses yet