A production-ready NestJS base project with industry-standard structure, secure bootstrap, typed configuration, validation, health checks, logging, Swagger docs, linting/formatting, and Docker setup.
- Typed configuration with validation (
@nestjs/config,joi) - Centralized bootstrap: global prefix, API versioning, CORS, Helmet, compression, cookies
- Global validation pipe (whitelist + transform)
- Structured logging with
nestjs-pino(pretty in dev) - Rate limiting via
@nestjs/throttler - Health checks with
@nestjs/terminusat/health - OpenAPI (Swagger) docs (configurable path)
- ESLint + Prettier configured
- Dockerfile and docker-compose for local/prod
src/
common/
filters/
interceptors/
config/
configuration.ts
validation.ts
modules/
health/
health.controller.ts
health.module.ts
app.controller.ts
app.module.ts
app.service.ts
main.ts
- Copy env and install dependencies:
cp .env.example .env
pnpm install- Run locally (watch):
pnpm run start:dev- Build and run prod:
pnpm run build
pnpm run start:prodEdit .env (all values validated):
- APP_NAME, NODE_ENV, HOST, PORT, GLOBAL_PREFIX
- LOG_LEVEL, LOG_PRETTY
- CORS_ENABLED, CORS_ORIGIN
- SWAGGER_ENABLED, SWAGGER_PATH, SWAGGER_TITLE, SWAGGER_DESCRIPTION, SWAGGER_VERSION
- RATE_LIMIT_TTL, RATE_LIMIT_LIMIT
- Hello:
GET /api/v1 - Health:
GET /health - Docs:
GET /docs(if enabled)
- build: clean and compile
- start: run compiled app
- start:dev: dev server with watch
- start:prod: production mode
- lint: lint and fix
- test, test:watch, test:cov, test:e2e
Build and run:
docker build -t base-api .
docker run -p 3000:3000 --env-file .env base-apiOr via compose:
docker-compose up --build- Use
v{n}URI versioning; add@Version('2')for new endpoints - Keep modules self-contained under
src/modules/<name> - Configuration under
src/configonly; do not readprocess.envelsewhere - Global concerns (filters, interceptors) under
src/common
UNLICENSED (customize as needed)