Bird
0
0

How do custom decorators in NestJS typically store metadata that can be later retrieved by the Reflector?

easy📝 Conceptual Q2 of 15
NestJS - Guards
How do custom decorators in NestJS typically store metadata that can be later retrieved by the Reflector?
ABy registering metadata in a global variable accessible to all modules.
BBy modifying the method's source code directly.
CBy using <code>SetMetadata</code> to attach key-value pairs to the target method or class.
DBy using environment variables to store metadata values.
Step-by-Step Solution
Solution:
  1. Step 1: Recall how metadata is set

    Custom decorators use SetMetadata to attach metadata key-value pairs.
  2. Step 2: Evaluate options

    Only By using SetMetadata to attach key-value pairs to the target method or class. correctly describes this standard approach; others are incorrect or impractical.
  3. Final Answer:

    By using SetMetadata to attach key-value pairs to the target method or class. -> Option C
  4. Quick Check:

    SetMetadata is the official way to store metadata in NestJS. [OK]
Quick Trick: SetMetadata attaches metadata key-value pairs [OK]
Common Mistakes:
  • Thinking metadata is stored in global variables
  • Assuming source code is modified
  • Using environment variables for metadata

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes