NestJS Best Practices
A condensed summary of the 25 most important NestJS practices for Node.js teams - drawn from every page in this section.
Search across all documentation pages
A condensed summary of the 25 most important NestJS practices for Node.js teams - drawn from every page in this section.
Use NestJS 11 on Node 24 LTS: Current major with Express 5 and Fastify 5 support - NestJS Basics.
Fastify adapter by default: 20-40% faster than Express adapter - NestJS Performance Reality.
One module per domain: UsersModule, OrdersModule, BillingModule. No god AppModule providers.
Export only what other modules need: Keep providers private by default.
Thin controllers: Delegate to services; controllers only handle HTTP concerns.
Injectable services for business logic: Testable, DI-wired, single responsibility.
Global ValidationPipe with whitelist: Strip unknown properties from DTOs.
DTOs with class-validator decorators: Every POST/PUT body typed and validated.
Guards for authentication: Not middleware, not interceptor - Guards, Interceptors & Pipes.
@Public() decorator for health/auth routes: K8s probes must not require tokens.
Selective interceptors: Not five global interceptors on every route.
PrismaService with lifecycle hooks: $connect on init, $disconnect on destroy - NestJS + Prisma/TypeORM.
Singleton providers by default: Request scope only for request-specific state.
Custom provider tokens for interfaces: Symbol + useClass for swappable implementations.
overrideProvider in tests: Mock database, email, and external clients.
ConfigModule global with validation: Joi or Zod schema on env at startup.
Global exception filter: Consistent error JSON across all endpoints.
setGlobalPrefix with health exclusion: /api/v1 for routes, /health bare.
Avoid circular dependencies: Refactor before forwardRef everywhere.
Message pattern versioning for microservices: order.create.v2 - Microservices Mode.
Hybrid HTTP + microservice for health: Keep HTTP health even with TCP transport.
Profile before blaming NestJS: Database is usually the bottleneck.
Return plain objects from services: Avoid class-transformer overhead on responses.
CLI for scaffolding: nest g module, nest g controller, nest g service.
Don't use NestJS for 5-endpoint APIs: Framework weight must match complexity.
Modular monoliths, teams wanting Spring-like structure, microservices with multiple transporters, and projects with 30+ endpoints.
Fastify unless a critical dependency requires Express. Performance difference is real.
Prisma for DX and migrations. TypeORM for decorator entities and existing TypeORM codebases. Pick one.
Max 2 controllers and 3-5 providers per feature module. Split when a module file exceeds 200 lines.
Only when you need event-driven or RPC communication between services. HTTP REST is simpler for most cases.
Stack versions: This page was written for Node.js 24.18.0 (Active LTS), npm 10+, TypeScript 5.6+, Express 5, Fastify 5, and NestJS 11.
Reviewed by Chris St. John·Last updated Jul 19, 2026