NestJS + Prisma + Vercel Starter
Minimal REST API built with NestJS, Prisma v6, PostgreSQL — ready for Vercel serverless deployment.
Why Prisma v6?
Prisma v7 introduced breaking changes that require extra serverless adapters and additional configuration files. Prisma v6 works with Vercel out of the box — no extra setup needed.
Quick Setup
1. Clone the repo
git clone https://github.com/nabinkdl/prisma-Nest-vercel-setup.git my-app
cd my-app
Rename the folder to whatever fits your project (
my-appabove). Then remove the original git history so you can start fresh:rm -rf .git git init
🏷️ Set Project Details (No manual editing)
Instead of editing package.json, run:
npm pkg set name="your name"
npm pkg set description="this is your description"
npm pkg set author=" set author name"
npm pkg set license=" set license"
2. Install
npm install
3. Configure environment
cp .env.example .env
Set DATABASE_URL in .env:
DATABASE_URL="postgresql://user:password@host:5432/mydb?schema=public"
| Provider | Connection string tip |
|---|---|
| Neon | append ?sslmode=require
|
| Supabase | append ?pgbouncer=true
|
| Railway | use the provided string as-is |
4. Migrate database
npx prisma migrate dev --name init
Prisma Studio
npx prisma studio
5. Start dev server
npm run start:dev
# → http://localhost:3000
Deploy to Vercel
- Push repo to GitHub
- Import project at vercel.com/new
- Add environment variables:
-
DATABASE_URL— your PostgreSQL connection string -
NODE_ENV—production
-
- Deploy — Vercel automatically runs:
prisma generate && npm run build
API Endpoints
| Method | Route | Body | Description |
|---|---|---|---|
| GET | / |
— | API info |
| GET | /todos |
— | List all todos |
| POST | /todos |
{ "title": "string" } |
Create a todo |
| DELETE | /todos/:id |
— | Delete a todo |
Project Structure
src/
├── app.module.ts # Root module
├── prisma/
│ ├── prisma.service.ts # Singleton Prisma client
│ └── prisma.module.ts # Global Prisma module
└── todo/
├── todo.controller.ts
├── todo.service.ts
└── todo.module.ts
api/
└── index.js # Vercel serverless entry point
prisma/
└── schema.prisma # Database schema
Notes
-
Singleton pattern —
PrismaServicereuses a single client instance across serverless invocations to prevent connection exhaustion. -
Two entry points —
main.tsis for local development only (app.listen(3000)). Vercel usesapi/index.jswithExpressAdapterand nolistencall. -
Never commit
.env— use.env.exampleas the template for your team. - Best for — hobby/small projects
Top comments (0)