Bird
0
0

Why might you prefer applying middleware to specific routes instead of globally in a NestJS application?

hard📝 Conceptual Q10 of 15
NestJS - Middleware
Why might you prefer applying middleware to specific routes instead of globally in a NestJS application?
ATo improve performance by limiting middleware to necessary routes
BBecause global middleware cannot access request objects
CTo avoid writing middleware classes
DBecause middleware cannot modify responses globally
Step-by-Step Solution
Solution:
  1. Step 1: Consider middleware impact on performance

    Applying middleware globally runs it on all routes, which may be unnecessary and slow down requests.
  2. Step 2: Understand benefits of selective application

    Applying middleware only where needed improves efficiency and reduces overhead.
  3. Final Answer:

    To improve performance by limiting middleware to necessary routes -> Option A
  4. Quick Check:

    Selective middleware improves performance [OK]
Quick Trick: Apply middleware selectively to boost app performance [OK]
Common Mistakes:
  • Thinking global middleware cannot access requests
  • Believing middleware avoids writing classes
  • Assuming middleware cannot modify responses globally

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes