05 / 05

What is the complete NestJS request lifecycle in order?

The full order is: Incoming request → Middleware → Guards → Interceptors (pre) → Pipes → Controller handler → Interceptors (post) → Exception Filters. Exception filters also catch exceptions thrown at any earlier stage. Middleware is the only layer that runs before routing and has no knowledge of which handler will be invoked.

Complete request lifecycle order:
  1. 1
    1. Incoming HTTP request hits the server.
  2. 2
    1. Middleware — runs before routing, has access to req/res, must call next().
  3. 3
    1. Guards — decide if the request is allowed to proceed (authentication/authorization).
  4. 4
    1. Interceptors (pre-controller) — transform or log before the handler runs.
  5. 5
    1. Pipes — validate and transform route params, query params, and body.
  6. 6
    1. Controller handler — executes your route method.
  7. 7
    1. Interceptors (post-controller) — transform the response on the way out.
  8. 8
    1. Exception filters — catch any unhandled exception and shape the error response.
Visualizing the pipeline in a single controller