Question · NestJS course · Module 2: Routing and Request Lifecycle

Basics: Middleware vs Guard

How does middleware differ from a guard in NestJS?

Answer options

  • Middleware has access to ExecutionContext, but a guard does not
  • A guard executes before middleware
  • Middleware and guard are exactly the same
  • Middleware executes before the guard and does not know the target route
Show the answer

Correct answer:

  • Middleware executes before the guard and does not know the target route