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.
For further actions, you may consider blocking this person and/or reporting abuse
