DEV Community

Nabin Kandel
Nabin Kandel

Posted on

Building a NestJS + Prisma + Vercel Serverless API :quick setup

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
Enter fullscreen mode Exit fullscreen mode

Rename the folder to whatever fits your project (my-app above). 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"
Enter fullscreen mode Exit fullscreen mode

2. Install

npm install
Enter fullscreen mode Exit fullscreen mode

3. Configure environment

cp .env.example .env
Enter fullscreen mode Exit fullscreen mode

Set DATABASE_URL in .env:

DATABASE_URL="postgresql://user:password@host:5432/mydb?schema=public"
Enter fullscreen mode Exit fullscreen mode
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
Enter fullscreen mode Exit fullscreen mode

Prisma Studio

 npx prisma studio
Enter fullscreen mode Exit fullscreen mode

5. Start dev server

npm run start:dev
# → http://localhost:3000
Enter fullscreen mode Exit fullscreen mode

Deploy to Vercel

  1. Push repo to GitHub
  2. Import project at vercel.com/new
  3. Add environment variables:
    • DATABASE_URL — your PostgreSQL connection string
    • NODE_ENVproduction
  4. Deploy — Vercel automatically runs:
   prisma generate && npm run build
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Notes

  • Singleton patternPrismaService reuses a single client instance across serverless invocations to prevent connection exhaustion.
  • Two entry pointsmain.ts is for local development only (app.listen(3000)). Vercel uses api/index.js with ExpressAdapter and no listen call.
  • Never commit .env — use .env.example as the template for your team.
  • Best for — hobby/small projects

Top comments (0)