Bird
0
0

Why are interceptors used to add cross-cutting logic in NestJS?

easy📝 Conceptual Q1 of 15
NestJS - Interceptors
Why are interceptors used to add cross-cutting logic in NestJS?
AThey allow code to run before and after method execution without changing business logic
BThey replace controllers to handle HTTP requests directly
CThey store data permanently in the database
DThey generate HTML views automatically
Step-by-Step Solution
Solution:
  1. Step 1: Understand the role of interceptors

    Interceptors run code before and after method calls, allowing extra logic without changing core business code.
  2. Step 2: Identify what cross-cutting logic means

    Cross-cutting logic is code that applies across many parts, like logging or timing, which interceptors handle well.
  3. Final Answer:

    They allow code to run before and after method execution without changing business logic -> Option A
  4. Quick Check:

    Cross-cutting logic = run code before/after method [OK]
Quick Trick: Interceptors wrap method calls to add extra logic easily [OK]
Common Mistakes:
  • Thinking interceptors replace controllers
  • Confusing interceptors with database storage
  • Assuming interceptors generate views

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes