Production-ready NestJS API starter with Prisma, Pino logging, Swagger, Throttler, and global exception handling.
- NestJS 11 — framework
- Prisma 6 — ORM + migrations
- nestjs-pino — structured JSON logging (pino-pretty in dev)
- @nestjs/swagger — OpenAPI docs at
/api/docs - @nestjs/throttler — rate limiting via global guard
- class-validator + class-transformer — DTO validation
- Vitest — unit testing
- Husky — Git hooks
- lint-staged — run Prettier only on staged files
- commitlint — enforce conventional commit format
- Prettier — code formatting
# 1. Install dependencies
pnpm install
# 2. Initialize Husky hooks (run once after cloning)
pnpm prepare
# 3. Configure environment
cp .env.example .env
# Edit DATABASE_URL and other vars
# 4. Generate Prisma client
pnpm prisma generate
# 5. Run migrations
pnpm prisma migrate dev --name init
# 6. Start dev server
pnpm devsrc/
├── main.ts # Bootstrap (CORS, Swagger, ValidationPipe)
├── app.module.ts # Root module (LoggerModule, PrismaModule, ThrottlerModule)
├── prisma/
│ ├── prisma.module.ts # Global Prisma module
│ └── prisma.service.ts # PrismaClient wrapper
└── common/
└── filters/
└── http-exception.filter.ts # Global exception filter
| Hook | What it does |
|---|---|
pre-commit |
Runs lint-staged (Prettier on staged files) |
commit-msg |
Validates commit message format (commitlint) |
Follows Conventional Commits:
<type>(<scope>): <description>
Allowed types: feat, fix, docs, refactor, test, chore, perf, style, ci, build, revert
pnpm prisma migrate dev --name <migration-name> # Create & apply migration
pnpm prisma migrate deploy # Apply migrations in production
pnpm prisma studio # Open Prisma Studio GUI
pnpm prisma generate # Regenerate client after schema changesnest g module <name>
nest g service <name>
nest g controller <name>Register the module in app.module.ts imports.
| Variable | Description | Default |
|---|---|---|
NODE_ENV |
development or production |
development |
PORT |
HTTP port | 3001 |
DATABASE_URL |
PostgreSQL connection string | — |
ALLOWED_ORIGINS |
Comma-separated CORS origins | http://localhost:3000 |
| Command | Description |
|---|---|
pnpm dev |
Dev server with hot-reload |
pnpm build |
Compile to dist/ |
pnpm start |
Run compiled build |
pnpm lint |
ESLint check |
pnpm test |
Run unit tests |
pnpm test:coverage |
Run tests with coverage |
pnpm prepare |
Install Husky hooks |