Web Framework Internals interview question · Most asked

What is the NestJS request lifecycle?

Summary

Middleware → guards → interceptors (before) → pipes → controller handler (and services) → interceptors (after) → response; exception filters handle errors thrown at any stage. Within each kind, global ones run before controller-level and route-level ones (pipes also apply per parameter).

Longer Answer

Because guards run before pipes, a guard sees the raw request, not the validated and transformed DTO. Use guards for identity and coarse permissions and do resource-level checks after validation.

Key Points

  • Middleware, guards, interceptors, pipes, handler.
  • Interceptors wrap the handler (before and after).
  • Exception filters catch errors from any stage.
  • Guards see raw input.

Deep dive: Request Lifecycle: NestJS: Middleware, Guards, Interceptors, Pipes and Filters

Explanation

What interviewers look for

Exact order and the guard-before-pipe implication.

More most-asked Web Framework Internals questions

← All Web Framework Internals questions