A minimal, production‑ready REST API with JWT authentication and todo CRUD, built with NestJS, Prisma v7, and PostgreSQL — optimised for Vercel serverless deployment.
Stop wrestling with boilerplate. Clone this, configure your database, and you've got a live API in minutes.
✨ What's included
- 🔐 JWT auth – register and login endpoints ready to go
- 📝 Full todo CRUD – each user manages their own private list
- 🧩 Clean NestJS architecture – separate modules for
auth,todo, and a sharedprismaservice - ⚡ Serverless‑ready – Prisma client singleton prevents connection exhaustion on Vercel
- 🛠️ Zero‑config deployment – push to GitHub, import to Vercel, done
⚡ Quick Setup
1. Clone and rename
git clone https://github.com/nabinkdl/Nest-setup my-app
cd my-app
Rename my-app to whatever fits your project. Then start fresh:
rm -rf .git && git init
2. Set project metadata (no manual editing)
npm pkg set name="your-name"
npm pkg set description="this is your description"
npm pkg set author="your name"
npm pkg set license="MIT"
3. Install dependencies
bun install # you can also use npm or yarn
4. Configure your database
cp .env.example .env
Open .env and add your PostgreSQL connection string:
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 |
5. Run the migration
bunx prisma migrate dev --name init
(Optional) Explore your data with Prisma Studio:
bunx prisma studio
6. Start developing
bun run start:dev
Your API is now live at http://localhost:3000 🎉
☁️ Deploy to Vercel
- Push your repo to GitHub.
- Import the project on vercel.com/new.
- Add the environment variables:
-
DATABASE_URL– your PostgreSQL connection string -
NODE_ENV–production
-
- Hit Deploy – Vercel will automatically run:
bunx prisma generate && bun run build
Your serverless NestJS API is now live!
📡 API Endpoints
All /todos routes require a JWT Bearer token in the Authorization header.
| Method | Route | Body (JSON) | Description |
|---|---|---|---|
| POST | /auth/register |
{"email": "user@test.com", "password": "123"} |
Register a new user |
| POST | /auth/login |
{"email": "user@test.com", "password": "123"} |
Login, receive a JWT |
| GET | /todos |
– | List all user's todos |
| GET | /todos/:id |
– | Get a single todo |
| POST | /todos |
{"title": "Buy milk"} |
Create a todo |
| PATCH | /todos/:id |
{"title": "Buy milk updated"} |
Update a todo |
| DELETE | /todos/:id |
– | Delete a todo |
Try it with curl, Postman, or your future frontend.
📁 Project Structure
src/
├── app.module.ts # Root module
├── app.controller.ts # Root controller
├── main.ts # App entry point
├── common/ # Shared utilities
│ ├── decorators/ # @CurrentUser, etc.
│ └── guards/ # JwtAuthGuard
├── core/
│ └── prisma/ # Prisma module & service (singleton)
└── modules/
├── auth/ # Auth module (register, login, JWT)
└── todo/ # Todo CRUD module
prisma/
├── schema.prisma # Database schema
└── migrations/ # Prisma migration files
Everything is intentionally minimal so you can understand and extend it with confidence.
💡 Notes
-
Singleton Prisma client – The
PrismaServicereuses a single client instance across serverless invocations to avoid exhausting database connections. -
Never commit
.env– use.env.exampleas a safe template for your team. - Best for – hobby projects, small startups, hackathons, or as a learning base. Need rate limiting or more complex logic? The architecture is clean enough to scale with your needs.
Top comments (0)