Node.js & Prisma Backend Setup
A simple, step-by-step guide to starting your backend project the right way—without the headache.
01Starting Your Project
First, let's create a folder for your project and get Node.js ready to go. Run these commands in your terminal:
mkdir forum-backend
cd forum-backend
npm init -y
npm install prisma typescript @types/node --save-dev
npx tsc --init
cd forum-backend
npm init -y
npm install prisma typescript @types/node --save-dev
npx tsc --init
02Connecting the Database
Now we connect Prisma to PostgreSQL. This creates the files needed to talk to your database.
npx prisma init --datasource-provider postgresql
Pro-tip: Update your .env file with your DATABASE_URL to match your local PostgreSQL setup!
The User Model
Open prisma/schema.prisma and define your User structure. This tells Prisma how your database table should look:
model User
id Int @id @default(autoincrement())
email String @unique
username String @unique
id Int @id @default(autoincrement())
email String @unique
username String @unique
1. Migrate
Run this to push your schema changes to the real database:
npx prisma migrate dev --name init2. Generate Client
Creates the type-safe helpers for your code:
npx prisma generate