Bird
0
0

Which method is used to apply middleware to specific routes in a NestJS module?

easy📝 Conceptual Q2 of 15
NestJS - Middleware
Which method is used to apply middleware to specific routes in a NestJS module?
AforRoutes()
Bapply()
Cuse()
DsetMiddleware()
Step-by-Step Solution
Solution:
  1. Step 1: Identify middleware application methods

    In NestJS, middleware is applied using consumer.apply() chained with forRoutes() to specify routes.
  2. Step 2: Recognize the method that defines routes

    forRoutes() specifies which routes the middleware applies to, not apply() or use().
  3. Final Answer:

    forRoutes() -> Option A
  4. Quick Check:

    Middleware route selection = forRoutes() [OK]
Quick Trick: Use forRoutes() to specify routes for middleware [OK]
Common Mistakes:
  • Using apply() alone without forRoutes()
  • Confusing use() with middleware application
  • Assuming setMiddleware() exists in NestJS

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes