0
0
NestJSframework~5 mins

Module decorator and metadata in NestJS - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the @Module decorator in NestJS?
The @Module decorator defines a module in NestJS. It organizes related components like controllers, providers, and imports into a single unit, helping structure the app clearly.
Click to reveal answer
beginner
Name the main metadata properties used inside the @Module decorator.
The main properties are: <br>• imports: other modules to include<br>• controllers: classes handling incoming requests<br>• providers: services or classes that provide functionality<br>• exports: providers made available to other modules
Click to reveal answer
intermediate
How does the 'imports' property in @Module metadata work?
The 'imports' property lists other modules whose exported providers are needed in this module. It allows sharing functionality between modules.
Click to reveal answer
intermediate
What happens if you forget to add a provider to the 'providers' array in a module?
NestJS will not recognize the provider as injectable in that module, causing errors when trying to use it in controllers or other providers.
Click to reveal answer
intermediate
Explain the role of the 'exports' property in the @Module decorator.
The 'exports' property makes selected providers available to other modules that import this module. It helps share services across different parts of the app.
Click to reveal answer
Which property in the @Module decorator lists the controllers of the module?
Acontrollers
Bproviders
Cimports
Dexports
What does the 'providers' array in a module contain?
AOther modules to import
BControllers for handling requests
CComponents for UI rendering
DServices and classes that provide functionality
If you want to use a service from another module, which property should you use in your module?
Acontrollers
Bproviders
Cimports
Dexports
What is the effect of adding a provider to the 'exports' array?
AIt makes the provider available to modules that import this module
BIt hides the provider from other modules
CIt registers the provider as a controller
DIt deletes the provider
Which decorator is used to define a module in NestJS?
A@Injectable
B@Module
C@Component
D@Controller
Describe how the @Module decorator organizes an application in NestJS.
Think about how a folder groups related files.
You got /3 concepts.
    Explain the roles of 'imports' and 'exports' in the @Module metadata.
    Consider how you borrow and lend things between friends.
    You got /3 concepts.