🔧 AI Nachrichten Opinion: Caution Needed in the AI Race(15.09.2026 um 18:55 Uhr)
🔧 AI Nachrichten Lima, Ohio, Passes 18-Month Data Center Moratorium(15.09.2026 um 18:56 Uhr)
🔧 AI Nachrichten A.I. Is Unpopular With Voters, a New York Times/Siena Poll Finds(15.09.2026 um 18:46 Uhr)
🔧 AI Nachrichten Meta expands subscription push with new AI-focused plans(15.09.2026 um 19:05 Uhr)
🔧 AI Nachrichten US military confirms it launched space weapons into Earth’s orbit(15.09.2026 um 19:09 Uhr)
🔧 AI Nachrichten Introducing Gemini 3.8 Live and 3.8 Live Extended Thinking(15.09.2026 um 19:05 Uhr)
🔧 AI Nachrichten Opinion: Caution Needed in the AI Race(15.09.2026 um 18:55 Uhr)
🔧 AI Nachrichten Lima, Ohio, Passes 18-Month Data Center Moratorium(15.09.2026 um 18:56 Uhr)
🔧 AI Nachrichten A.I. Is Unpopular With Voters, a New York Times/Siena Poll Finds(15.09.2026 um 18:46 Uhr)
🔧 AI Nachrichten Meta expands subscription push with new AI-focused plans(15.09.2026 um 19:05 Uhr)
🔧 AI Nachrichten US military confirms it launched space weapons into Earth’s orbit(15.09.2026 um 19:09 Uhr)
🔧 AI Nachrichten Introducing Gemini 3.8 Live and 3.8 Live Extended Thinking(15.09.2026 um 19:05 Uhr)

🔧 Programmierung 🕛 vor 11 Monaten 6 Min Lesezeit
0

Setting Up Prisma + PostgreSQL in a Monorepo (TurboRepo + PNPM + Node.js)

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

In this post, we’ll learn how to set up Prisma with PostgreSQL inside a TurboRepo monorepo, using PNPM workspaces, Node.js, and Docker for the database.



By the end, you’ll have a working Express.js API that connects to a PostgreSQL database via Prisma ORM — all inside a clean, shareable monorepo structure.









What Is a Monorepo?



A monorepo (short for monolithic repository) is a way of organizing multiple apps and packages under one codebase — with shared dependencies, tools, and configs.



For example:



to install.








Step 1 : Create the TurboRepo Monorepo






CODE
pnpm dlx create-turbo@latest






When prompted:




  • Select . to create inside your current folder.

  • Choose PNPM as the package manager.



After setup, you’ll see folders like apps/docs and apps/web.

Delete the docs app — we’ll only keep the web app for now.







Step 2 : Create a Node.js Backend (http-server)



Inside the apps folder, create a new project folder:




CODE
cd apps
mkdir http-server
cd http-server
npm init -y






Your package.json should look like this:




CODE
{
"name": "http-server",
"version": "1.0.0",
"type": "commonjs",
"main": "index.js",
"scripts": {
"build": "tsc -b",
"start": "node dist/index.js",
"dev": "npm run build && npm run start"
}
}









What These Scripts Do:





  • build → Compiles TypeScript to JavaScript in the dist folder.


  • start → Runs the built JS file (dist/index.js).


  • dev → Builds the code, then starts the server (useful in development).









Step 3 : Create a tsconfig.json



Inside apps/http-server, add:




CODE
{
"extends": "@repo/typescript-config/base.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist"
}
}






👉 This tells TypeScript where to find the source files (src) and where to put compiled files (dist).



Now create:




CODE
mkdir src
touch src/index.ts












Step 4 : Add Dependencies



Install dependencies for the backend:




CODE
pnpm add express @types/express bcryptjs @types/bcryptjs cors @types/cors






And link the shared TypeScript config from the monorepo:




CODE
"dependencies": {
"@repo/typescript-config": "workspace:*"
}






Then run:




CODE
pnpm install












Step 5 : Create a Shared Database Package



In the packages folder, create database:




CODE
cd ../../packages
mkdir database
cd database
npm init -y






Update the package.json:




CODE
{
"name": "@repo/database",
"version": "1.0.0",
"type": "commonjs",
"main": "index.js",
"dependencies": {
"@repo/typescript-config": "workspace:*"
}
}






And add a TypeScript config file:




CODE
{
"extends": "@repo/typescript-config/base.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist"
}
}









Why Create These Files?





  • package.json: Defines this as a workspace package that other apps (like http-server) can import.


  • tsconfig.json: Tells TypeScript how to compile code in this package.









Step 6 : Install and Setup Prisma



Inside packages/database:




CODE
pnpm add prisma @prisma/client
pnpm prisma init









What These Commands Do:





  • pnpm add prisma @prisma/client → Installs Prisma ORM and its generated client.


  • pnpm prisma init → Creates a prisma folder with a schema.prisma file and .env.









Step 7 : Configure Prisma Schema



Open prisma/schema.prisma and replace it with:




CODE
generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

model User {
id String @id @default(uuid())
name String
email String @unique
password String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}












Step 8 : Setup the Environment Variable



In packages/database/.env, add your PostgreSQL connection string:




CODE
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/monorepo-prisma"












Step 9 : Run Prisma Commands



Run the migration and generate the Prisma client:




CODE
npx prisma migrate dev --name init_user_model






👉 This creates a migration file in /prisma/migrations and applies it to your PostgreSQL database.




CODE
npx prisma studio






👉 Opens Prisma Studio — a beautiful web UI to view and edit your database data.




CODE
npx prisma generate






👉 Generates the Prisma client that you’ll use in your code to query the database.









Step 10 : Export the Prisma Client



Inside packages/database/src/index.ts:




CODE
import { PrismaClient } from "@prisma/client";

export const prisma = new PrismaClient();






Then update your package.json exports:




CODE
{
"name": "@repo/database",
"version": "1.0.0",
"type": "module",
"main": "index.js",
"exports": {
"./config": "./src/index.ts"
},
"dependencies": {
"@prisma/client": "^6.17.1",
"prisma": "^6.17.1",
"@repo/typescript-config": "workspace:*"
}
}












Step 11 : Connect Prisma in the Express Server



Go to your apps/http-server/src/index.ts and paste this:




CODE
import express, { Request, Response } from "express";
import { prisma } from "@repo/database/config";
import bcrypt from "bcryptjs";
import cors from "cors";

const app = express();

app.use(express.json());
app.use(cors());

app.post("/api/register", async (req: Request, res: Response) => {
try {
const { name, email, password } = req.body;

if (!name || !email || !password) {
return res.status(400).json({ error: "All fields are required" });
}

const existingUser = await prisma.user.findUnique({ where: { email } });
if (existingUser) {
return res.status(409).json({ error: "User already exists" });
}

const hashedPassword = await bcrypt.hash(password, 10);

const user = await prisma.user.create({
data: { name, email, password: hashedPassword },
select: { id: true, name: true, email: true },
});

res.status(201).json({ message: "User registered successfully", user });
} catch (error) {
console.error("Error while registering user:", error);
res.status(500).json({ error: "Internal server error" });
}
});

app.listen(3001, () => console.log("🚀 Server is running on port 3001"));












Step 12 : Link Everything Together



Add this to apps/http-server/package.json:




CODE
"dependencies": {
"@repo/database": "workspace:*"
}






Then in the root of your project, run:




CODE
pnpm install












Step 13 : Test the API



Run your server:




CODE
pnpm dev --filter http-server






Now test the /api/register endpoint using Postman:




CODE
POST http://localhost:3001/api/register






Body (JSON):




CODE
{
"name": "Waseem Adil",
"email": "[email protected]",
"password": "12345678"
}






If everything works, you’ll see:




CODE
{
"message": "User registered successfully",
"user": {
"id": "uuid-generated",
"name": "Waseem Adil",
"email": "[email protected]"
}
}












Final Project Structure











Summary











































Step Command / Concept Explanation
pnpm dlx create-turbo@latest Creates a new monorepo TurboRepo project setup
pnpm add prisma @prisma/client Installs Prisma ORM ORM + generated client
pnpm prisma init Initializes Prisma Creates schema + .env
npx prisma migrate dev Creates migration + syncs DB Updates schema in Postgres
npx prisma studio Opens Prisma UI View/Edit database data
npx prisma generate Generates client Makes PrismaClient usable in code








What Is Prisma?



Prisma is an ORM (Object-Relational Mapper) for Node.js and TypeScript.

It helps you interact with your database (Postgres, MySQL, etc.) using clean TypeScript code instead of writing raw SQL.



Example:




CODE
const users = await prisma.user.findMany();






is equivalent to:




CODE
SELECT * FROM users;












🎉 That’s It!

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
No Head in the Clouds! How Healthcare Providers Can Avert Cloud Security Breaches
1 Quelle
Magic Out-Of-The-Box — Does It Apply to SIEM Solutions?
1 Quelle
Vulnerability Assessment vs. Penetration Testing
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Setting Up Prisma + PostgreSQL in a Monorepo (TurboRepo + PNPM + Node.js)

Thematisch verwandte Begriffe: Setting, Prisma, PostgreSQL, Monorepo · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...