Recall & Review
beginner
What is the purpose of the Reflector class in NestJS?Reflector helps read metadata set by decorators on classes, methods, or properties. It allows you to access custom data attached to these elements at runtime.
Click to reveal answer
beginner
How do you create a custom decorator in NestJS?
You create a custom decorator by defining a function that uses the SetMetadata() helper to attach metadata to a target, like a class or method.Click to reveal answer
intermediate
Explain how custom decorators and Reflector work together in NestJS.
Custom decorators add metadata to classes or methods. Reflector reads this metadata during runtime, often inside guards or interceptors, to change behavior based on that metadata.
Click to reveal answer
intermediate
What is the syntax to read metadata using Reflector inside a guard?
Use `const value = this.reflector.get('key', context.getHandler())` to get metadata with key 'key' from the current method handler.Click to reveal answer
intermediate
Why use custom decorators instead of hardcoding values in guards or controllers?
Custom decorators keep code clean and reusable by separating metadata from logic. They make it easy to add or change behavior without modifying guard or controller code directly.
Click to reveal answer
What does the Reflector class in NestJS primarily do?
✗ Incorrect
Reflector reads metadata attached by decorators on classes or methods.
Which helper function is commonly used to create custom decorators in NestJS?
✗ Incorrect
SetMetadata() attaches custom metadata to classes or methods.
Where do you usually use Reflector to read metadata?
✗ Incorrect
Guards and interceptors often read metadata to decide behavior.
What argument does Reflector.get() require to read method metadata?
✗ Incorrect
Reflector.get() needs the metadata key and the method handler (context.getHandler()).
Why is using custom decorators beneficial in NestJS?
✗ Incorrect
Custom decorators keep code clean and reusable by separating metadata from logic.
Describe how to create and use a custom decorator with Reflector in NestJS.
Think about how metadata flows from decorator to runtime reading.
You got /5 concepts.
Explain why Reflector and custom decorators improve code organization in NestJS applications.
Consider how metadata helps keep code clean and flexible.
You got /5 concepts.