Mar 14 2024
NodeJS with Prisma and MySQL
Create project setup
As a first step, create a project directory and navigate into it:
mkdir hello-prisma
cd hello-prisma
Next, initialize a TypeScript project:
npm init -y
npm install prisma typescript ts-node @types/node --save-dev
npx tsc --init
More information with Prisma.
Quickstart
A simple of index.ts
file.
import { PrismaClient } from "@prisma/client";
import express from "express";
const prisma = new PrismaClient();
const app = express();
app.use(express.json());
app.get("/", async (req, res) => {
res.json({ message: "Welcome to Prisma" });
});
import userRoutes from "./routes/user.route";
import postRoutes from "./routes/post.route";
app.use("/users", userRoutes);
app.use("/posts", postRoutes);
const port = 1234;
app.listen(port, () => {
console.log(`
🚀 Server ready at: http://localhost:${port}
⭐️ See sample requests: http://pris.ly/e/ts/rest-express#3-using-the-rest-api`);
});
Github repository
Related projects