- Prepare the folder
mkdir 02-express-prisma
cd 02-express-prisma
- Init
npm
for start the project.
npm init -y
- Install the library
npm install express @prisma/client morgan cors bcrypt jsonwebtoken
npm install prisma nodemon dotenv --save-dev
- Create new file
index.js
touch index.js
- Copy this script into
index.js
const express = require("express");
const morgan = require("morgan");
const cors = require("cors");
const app = express();
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(cors());
app.use(morgan("dev"));
app.get("/", (req, res) => {
res.json({ msg: "Hello Express" });
});
app.listen(3000, () => {
console.log("Running on localhost:3000");
});
- Create schema.prisma
mkdir prisma && touch ./prisma/schema.prisma
- Copy this file into
schema.prisma
datasource db {
provider = "sqlite"
url = "file:../db/dev.db"
}
generator client {
provider = "prisma-client-js"
}
- Whenever you make changes to your database that are reflected in the Prisma schema, you need to manually re-generate Prisma Client to update the generated code in the
node_modules/.prisma/client
directory and update themigration
:
npx prisma generate
npx prisma migrate dev