Greg Thomas
Greg Thomas

Reputation: 557

What is the precise order of execution between middleware, guards, interceptors, pipes, filters, etc?

NestJS includes a lot of tools that seem to function as specialized versions of middleware like guards, interceptors, and filters.

What is the order of execution between all of these?

My understanding is that the order of execution goes like this:

Middleware -> Guards -> Interceptors -> Pipes -> Controllers -> Interceptors -> res.on('finish') handlers set up in middleware

Upvotes: 10

Views: 8444

Answers (1)

Jay McDoniel
Jay McDoniel

Reputation: 70191

This is commented on in the docs

Your understanding though, is correct, the docs go into a bit more detail when it comes to running multiple of each type and how they order at that point. Definitely worth the read.

Upvotes: 7

Related Questions