← All topics

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.

Questions by level

Sample questions

A few questions from each level with the correct answer and an explanation.

NestJS · Junior

  1. 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.

  2. Which HTTP platform does NestJS use by default?

    Correct answer: Express

    Express is the default adapter. You can switch to Fastify with @nestjs/platform-fastify for better performance, keeping most of your code unchanged.

  3. How do you create a new NestJS project?

    Correct answer: npx @nestjs/cli new my-app (or nest new my-app with the CLI installed)

    The CLI creates main.ts, a root AppModule, a sample controller and service, plus test setup. nest generate (nest g) adds modules, controllers and services.

  4. 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.

All 75 questions with answers →

NestJS · Middle

  1. 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.

  2. 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 microservices

    Middleware doesn't know which route handler will run. Guards are designed for 'may this request proceed?' decisions.

  3. What is ExecutionContext used 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() and context.getType() are the common calls.

  4. 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.

All 75 questions with answers →

NestJS · Senior

  1. How does Nest know what to inject into constructor(private users: UsersService)?

    Correct answer: TypeScript emits design:paramtypes metadata (with emitDecoratorMetadata), and Nest reads it via reflect-metadata to look up providers by class token

    That's why type-only imports (import type) or interfaces break injection: there is no runtime value to use as a token.

  2. 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.

  3. 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.

  4. 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.

All 75 questions with answers →

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 →