Bird
0
0

What is the primary purpose of an interceptor in NestJS?

easy📝 Conceptual Q11 of 15
NestJS - Interceptors
What is the primary purpose of an interceptor in NestJS?
ATo run code before and after a request is handled
BTo define database schemas
CTo handle HTTP routing
DTo manage user authentication
Step-by-Step Solution
Solution:
  1. Step 1: Understand the role of interceptors

    Interceptors in NestJS are designed to execute code before and after the main request handler runs.
  2. Step 2: Compare with other options

    Database schemas, routing, and authentication are handled by other parts of NestJS, not interceptors.
  3. Final Answer:

    To run code before and after a request is handled -> Option A
  4. Quick Check:

    Interceptor purpose = run code before/after request [OK]
Quick Trick: Interceptors wrap request handling with extra code [OK]
Common Mistakes:
  • Confusing interceptors with middleware
  • Thinking interceptors handle routing
  • Assuming interceptors manage authentication

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes