59 NestJS interview questions with answers
59 NestJS interview questions with detailed answers, sorted from basic to advanced. Free to practice, with progress saved automatically.
All NestJS interview questions
What is NestJS? Why use NestJS instead of plain Express?
What is a Module in NestJS? Explain the @Module decorator structure.
What does a Controller do in NestJS? How to define routes with decorators?
How do Providers and Dependency Injection work in NestJS?
Explain the NestJS Request Lifecycle: Middleware → Guards → Interceptors → Pipes → Controller → Exception Filters.
What are Guards in NestJS? How to implement a JWT Auth Guard?
What are Pipes in NestJS? How to use ValidationPipe with class-validator?
How do Interceptors work in NestJS? List common use cases.
What are Exception Filters in NestJS? How to create a global error handler.
How to integrate TypeORM with NestJS? How does the Repository pattern work?
Implement JWT Authentication flow in NestJS with @nestjs/jwt and Passport?
How do ConfigModule and ConfigService work in NestJS?
How to write unit tests and integration tests in NestJS?
How do NestJS Microservices work? What are the common transport layers?
Prisma with NestJS — setup and comparison with TypeORM?
File upload in NestJS with Multer — single, multiple files and validation?
Custom Decorators in NestJS — how to create @CurrentUser, @Roles, @Public?
WebSockets in NestJS — how to implement real-time features with @WebSocketGateway?
NestJS performance optimization: Fastify, Caching, Compression, Rate Limiting?
Middleware in NestJS — functional vs class middleware, apply by routes?
Swagger / OpenAPI documentation in NestJS — setup and common annotations?
Provider scopes in NestJS: DEFAULT, REQUEST, TRANSIENT — what are the differences?
Dynamic Modules in NestJS — forRoot and forRootAsync patterns?
Hierarchical Dependency Injection in NestJS — module hierarchy and provider lookup?
Custom providers: useValue, useClass, useFactory, useExisting — when to use each?
What is ExecutionContext in NestJS? How to switch between HTTP and WebSocket context?
RBAC (Role-Based Access Control) with custom Guards and Decorators in NestJS?
Transactions in TypeORM with NestJS — how to implement correctly?
TypeORM migrations — workflow and production best practices?
TypeORM Query Builder vs Repository API — when to use each?
Refresh token strategy in NestJS — implementing rotation and revocation?
Helmet, CORS, Rate Limiting — security hardening for NestJS APIs?
Session vs JWT — when to use each in NestJS?
Kafka integration with NestJS Microservices — producer and consumer setup?
Hybrid application in NestJS — serving HTTP and Microservice transport simultaneously?
Mocking providers in NestJS unit tests — TestingModule and jest.fn()?
E2E tests with Supertest in NestJS — setup and best practices?
Structured logging with Winston in NestJS?
Health checks and graceful shutdown in NestJS production?
Event Emitter in NestJS — @OnEvent and EventEmitter2?
Pagination in NestJS — Cursor-based vs Offset-based?
Serialization and response transformation with class-transformer in NestJS?
Soft delete and audit timestamps with TypeORM — createdAt, updatedAt, deletedAt?
API Key authentication and multi-tenant patterns in NestJS?
Caching with Redis in NestJS — CacheModule, TTL strategy and cache invalidation?
gRPC in NestJS — setup and comparison with REST?
Connection pooling and database performance optimization in NestJS?
Scheduler and CRON jobs in NestJS with @nestjs/schedule?
Request validation with nested DTOs, arrays, and conditional validation?
Docker and NestJS deployment — multi-stage build and containerization?
Error handling and Dead Letter Queue (DLQ) in NestJS Microservices?
A NestJS app fails with `Nest can't resolve dependencies of the OrderService (?)` — what causes it and how do you read that message?
Why must role checks that read `@Roles()` metadata live in a Guard rather than in NestJS middleware?
How do you configure `ValidationPipe` to reject unknown fields and coerce query params? What do `whitelist`, `forbidNonWhitelisted` and `transform` each do?
What is the difference between registering a global exception filter with `app.useGlobalFilters()` versus the `APP_FILTER` token?
How do `@MessagePattern` and `@EventPattern` differ in NestJS Microservices, and when do you pick each?
Two NestJS modules import each other and create a circular dependency — how do you handle it, and why keep `forwardRef` as a last resort?
How do you inject by interface in NestJS (for example swapping `PaymentGateway` between SePay and Stripe)?
What is `ModuleRef` for, and how do you obtain a REQUEST-scoped provider outside an HTTP request?