95 questions in 9 topics
NestJS Basics Interview Questions
What NestJS is, how it relates to Express, decorators, the CLI and a first controller.
- What is NestJS?
- What is the difference between NestJS and Express?
- What are decorators in NestJS and how do they work?
- What does the Nest CLI do, and which commands should you know?
NestJS Modules, Controllers and Providers Questions
How modules group code, what they export, dynamic modules, lifecycle hooks and route order.
- What is a module in NestJS?
- What is a provider in NestJS?
- What goes in a controller and what goes in a service?
- Why does Nest say it "can't resolve dependencies" when a service from another module is injected?
NestJS Dependency Injection Interview Questions
Tokens, custom providers, useFactory, scopes, circular dependencies and forwardRef.
- What is dependency injection in NestJS?
- How does Nest know which instance to inject, and can you inject an interface?
- What are
useValue,useClass,useFactoryanduseExisting? - How do you create a provider that needs an async setup, like a database connection?
NestJS Middleware, Guards and Interceptors Questions
What runs before and after a route handler, in which order, and when to use each piece.
- In what order do middleware, guards, interceptors, pipes and filters run in NestJS?
- How do you write and apply middleware in NestJS?
- What is the difference between middleware and a guard?
- What is a guard in NestJS? Show a role check.
NestJS Validation, Pipes and DTO Interview Questions
DTOs, ValidationPipe options, built-in and custom pipes, Zod schemas and response serialization.
- What is a DTO in NestJS, and why is it a class and not an interface?
- How do you validate a request body in NestJS?
- What do
whitelistandforbidNonWhitelisteddo inValidationPipe? - What does
transform: truedo, and why does"20"still fail@IsInt()?
NestJS Database Interview Questions
Connecting TypeORM, Prisma and Mongoose, transactions, migrations and N+1 queries.
- How do you connect NestJS to a SQL database with TypeORM?
- Why should
synchronize: truenever be used in production? - How do you use Prisma in a NestJS application?
- How do you use MongoDB with Mongoose in NestJS?
NestJS Testing Interview Questions
Unit tests with the testing module, mocks and overrides, e2e tests, Jest and Vitest.
- How do you write a unit test for a NestJS service?
- How do you replace a real dependency with a mock in a NestJS test?
- Jest or Vitest for NestJS tests?
- How do you write an end-to-end test for a NestJS API?
NestJS Microservices and GraphQL Interview Questions
Message transports, GraphQL, WebSockets, queues, cron jobs, server-sent events, versioning and caching.
- What does
@nestjs/microservicesprovide? - What is the difference between
@MessagePatternand@EventPattern? - Why does
client.send()do nothing until you subscribe? - What is the difference between code first and schema first GraphQL in NestJS?
Advanced NestJS Interview Questions
Architecture, CQRS, performance, security, configuration, logging and upgrading to NestJS 12.
- How would you structure a large NestJS codebase?
- What is CQRS, and how does
@nestjs/cqrsimplement it? - How do you make a NestJS API faster?
- How do you shut down a NestJS service gracefully?
Frequently Asked Questions
How do I prepare for a NestJS interview?
Build one small API end to end: a feature module, a DTO with validation, a guard for auth, a database with migrations, and a unit and an e2e test. Then be able to explain the request lifecycle order, provider scopes and how modules share providers. Review Node.js basics too, since interviewers often start there.
What NestJS questions are asked to freshers and to experienced developers?
Freshers get definitions with a small example: what Nest is, modules, controllers, providers, decorators, DTOs and pipes. With a few years of experience, expect dependency injection scopes, guards versus middleware, interceptors, testing and database transactions. Senior rounds ask about architecture, microservices, performance, security and upgrades.
Do I need to know Express before learning NestJS?
It helps. Nest runs on Express by default, so middleware, the request and response objects and error handling work the same way underneath, and interviewers often ask how Nest compares. A week with plain Express and the Node.js event loop makes Nest's abstractions easier to explain; the Node.js interview questions cover that ground.
Is TypeScript required for NestJS interviews?
In practice, yes. Nest is written in TypeScript and its dependency injection depends on decorators and type metadata, so expect questions on classes, interfaces versus classes, generics and decorators. Plain JavaScript is possible but rare in production Nest code.
How long does it take to prepare for a NestJS interview?
It depends on what you already know. With Node.js and TypeScript in hand, a plan of about two weeks covers it: one to build a small API covering modules, validation, auth and a database, and one for testing, microservices concepts and mock interviews. Starting from JavaScript only, add a week or two of TypeScript first.