Bird
0
0

Given the following middleware setup in NestJS:

medium📝 component behavior Q13 of 15
NestJS - Middleware
Given the following middleware setup in NestJS:
apply(authMiddleware, loggerMiddleware).forRoutes('users')
What will be the order of middleware execution when a request hits the 'users' route?
AauthMiddleware runs first, then loggerMiddleware
BloggerMiddleware runs first, then authMiddleware
CBoth run simultaneously
DOnly authMiddleware runs
Step-by-Step Solution
Solution:
  1. Step 1: Identify middleware order in apply()

    Middleware listed first runs first; here, authMiddleware is first.
  2. Step 2: Confirm sequence on route match

    When a request matches 'users', authMiddleware runs before loggerMiddleware.
  3. Final Answer:

    authMiddleware runs first, then loggerMiddleware -> Option A
  4. Quick Check:

    apply order = execution order [OK]
Quick Trick: First middleware in apply() runs first [OK]
Common Mistakes:
  • Assuming middleware run simultaneously
  • Thinking last middleware runs first
  • Ignoring route matching

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes