NestJS Interview Questions and Answers
Modules, controllers and providers, dependency injection, pipes, guards, interceptors and filters, validation, TypeORM and Prisma, testing, microservices and GraphQL.
225 questions for NestJS interviews with answers and explanations - Junior, Middle and Senior levels. Sample questions, online quizzes and coding tasks.
- Modules
- DI
- Guards
- Interceptors
- Testing
Questions by level
Junior
Core concepts and syntax · 50 questions
Middle
Practice, nuances and optimization · 50 questions
Senior
Architecture, internals, edge cases · 50 questions
Sample questions
A few questions from each level with the correct answer and an explanation.
NestJS · Junior
- What is NestJS?
Correct answer: A Node.js framework for building server-side applications in TypeScript, with modules, dependency injection and decorators
Nest gives a structured architecture inspired by Angular. Under the hood it runs on an HTTP framework, Express by default or Fastify, and adds modules, DI, pipes, guards and more.
- Which HTTP platform does NestJS use by default?
Correct answer: Express
Express is the default adapter. You can switch to Fastify with
@nestjs/platform-fastifyfor better performance, keeping most of your code unchanged. - How do you create a new NestJS project?
Correct answer:
npx @nestjs/cli new my-app(ornest new my-appwith the CLI installed)The CLI creates
main.ts, a rootAppModule, a sample controller and service, plus test setup.nest generate(nest g) adds modules, controllers and services. - What language does NestJS primarily use?
Correct answer: TypeScript (plain JavaScript is also supported)
Nest relies on TypeScript decorators and type metadata for dependency injection, so TypeScript is the natural choice.
NestJS · Middle
- In what order do Nest's request-processing layers run?
Correct answer: Middleware → guards → interceptors (before) → pipes → handler → interceptors (after) → exception filters (on error)
Within each layer, global ones run first, then controller-level, then route-level. Exception filters handle errors thrown anywhere along the way.
- Why should authentication be a guard rather than middleware?
Correct answer: Guards have the
ExecutionContext, so they know which handler and metadata (roles,@Public()) apply, and they work across HTTP, GraphQL and microservicesMiddleware doesn't know which route handler will run. Guards are designed for 'may this request proceed?' decisions.
- What is
ExecutionContextused for?Correct answer: It gives guards and interceptors the current handler, class and request, and lets one implementation work for HTTP, RPC and WebSockets
context.switchToHttp().getRequest(),context.getHandler(),context.getClass()andcontext.getType()are the common calls. - How can an interceptor wrap every response in
{ data: ... }?Correct answer:
return next.handle().pipe(map((data) => ({ data })))Interceptors are the place for cross-cutting response changes. Be consistent: errors are shaped by exception filters, not interceptors.
NestJS · Senior
- How does Nest know what to inject into
constructor(private users: UsersService)?Correct answer: TypeScript emits
design:paramtypesmetadata (withemitDecoratorMetadata), and Nest reads it viareflect-metadatato look up providers by class tokenThat's why type-only imports (
import type) or interfaces break injection: there is no runtime value to use as a token. - Why can a bundler or compiler without decorator metadata support break a Nest app?
Correct answer: Without
design:paramtypes, Nest can't resolve constructor dependencies by type, so injection fails unless every parameter uses@Inject(token)esbuild, for example, doesn't emit decorator metadata. SWC supports it with the right config, which is why Nest documents an SWC setup.
- How is the DI container organized across modules?
Correct answer: Each module has its own injector scope; providers are visible inside the module and in modules that import it only if exported
This encapsulation is why the same class listed in two modules' providers results in two instances.
- A REQUEST-scoped provider is injected into a singleton service. What happens?
Correct answer: The service and its consumers become request-scoped too, so the whole chain is instantiated per request
Scope bubbles up. In a busy app this can multiply allocations per request; durable providers or ALS are alternatives for multi-tenancy.
Combined quizzes with this topic
Questions from several topics at once - just like an interview for a specific role.
Coding tasks
Write your solution right in the browser, and tests check it instantly. JavaScript interview classics (debounce, deepClone, Promise.all, an LRU cache) and React components and hooks like a todo list, tabs, useDebounce and useInterval.
Open tasks →