Bird
0
0

Which NestJS method is used to apply middleware globally in the main application file?

easy📝 Conceptual Q2 of 15
NestJS - Middleware
Which NestJS method is used to apply middleware globally in the main application file?
Aapp.use()
Bapp.listen()
Capp.setGlobalPrefix()
Dapp.enableCors()
Step-by-Step Solution
Solution:
  1. Step 1: Recall middleware application

    Middleware is applied using the use() method on the app instance.
  2. Step 2: Identify global middleware method

    app.use() applies middleware globally to all routes.
  3. Final Answer:

    app.use() -> Option A
  4. Quick Check:

    Global middleware method = app.use() [OK]
Quick Trick: Use app.use() to apply middleware globally [OK]
Common Mistakes:
  • Using app.listen() to apply middleware
  • Confusing setGlobalPrefix with middleware
  • Thinking enableCors applies middleware

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes