Bird
0
0

In NestJS, when multiple middleware are applied using apply(), which middleware runs first during a request?

easy📝 Conceptual Q1 of 15
NestJS - Middleware
In NestJS, when multiple middleware are applied using apply(), which middleware runs first during a request?
AThe first middleware passed to <code>apply()</code> runs first
BThe last middleware passed to <code>apply()</code> runs first
CMiddleware run in alphabetical order
DMiddleware run in reverse order of declaration
Step-by-Step Solution
Solution:
  1. Step 1: Understand middleware application order

    In NestJS, middleware are executed in the order they are passed to the apply() method.
  2. Step 2: Identify which middleware runs first

    The first middleware listed runs first, then the next, and so on.
  3. Final Answer:

    The first middleware passed to apply() runs first -> Option A
  4. Quick Check:

    Middleware order = first passed runs first [OK]
Quick Trick: Middleware run in the order you list them [OK]
Common Mistakes:
  • Assuming last middleware runs first
  • Thinking middleware run alphabetically
  • Believing middleware run in reverse order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes