Bird
0
0

If you configure middleware in NestJS as:

medium📝 component behavior Q4 of 15
NestJS - Middleware
If you configure middleware in NestJS as:
apply(rateLimitMiddleware, corsMiddleware).forRoutes('orders')

Which middleware executes first when a request is made to the 'orders' route?
AcorsMiddleware
BrateLimitMiddleware
CBoth run simultaneously
DDepends on route configuration
Step-by-Step Solution
Solution:
  1. Step 1: Understand middleware order

    Middleware functions run in the order they are passed to apply().
  2. Step 2: Identify first middleware

    Here, rateLimitMiddleware is first, so it runs before corsMiddleware.
  3. Final Answer:

    rateLimitMiddleware -> Option B
  4. Quick Check:

    Order in apply() determines execution sequence [OK]
Quick Trick: First middleware in apply() runs first [OK]
Common Mistakes:
  • Assuming last middleware runs first
  • Thinking middleware run in parallel
  • Believing route affects middleware order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes