Skip to content

atheo810/02-express-prisma

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Express and Prisma

Step-step

  1. Prepare the folder
mkdir 02-express-prisma
cd 02-express-prisma
  1. Init npm for start the project.
npm init -y
  1. Install the library
npm install express @prisma/client morgan cors bcrypt jsonwebtoken
npm install prisma nodemon dotenv --save-dev
  1. Create new file index.js
touch index.js
  1. 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");
});
  1. Create schema.prisma
mkdir prisma && touch ./prisma/schema.prisma
  1. Copy this file into schema.prisma
datasource db {
  provider = "sqlite"
  url      = "file:../db/dev.db"
}

generator client {
  provider = "prisma-client-js"
}
Note
  1. 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 the migration:
npx prisma generate
npx prisma migrate dev

About

Create Express with Prisma ORM

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%