0
0
NestJSframework~5 mins

Shared modules in NestJS - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a shared module in NestJS?
A shared module is a module that exports providers, components, or services so other modules can use them without redefining. It helps reuse code across the app.
Click to reveal answer
beginner
How do you make a module shared in NestJS?
You export the providers or components inside the module's @Module decorator using the 'exports' array. Then import this module in other modules to use the shared parts.
Click to reveal answer
intermediate
Does importing a shared module multiple times create multiple instances of its providers in NestJS?
No, NestJS automatically shares a single instance of providers across all modules that import it.
Click to reveal answer
beginner
What is the difference between 'imports' and 'exports' in a NestJS module?
'imports' bring in other modules to use their exported providers. 'exports' make providers from the current module available to other modules that import it.
Click to reveal answer
intermediate
Can a shared module import other modules? What happens then?
Yes, a shared module can import other modules. Those imported modules' exported providers become available inside the shared module, but are not automatically exported to modules importing the shared module.
Click to reveal answer
What must you do to make a service available to other modules in NestJS?
AAdd the service to the module's exports array
BAdd the service to the module's imports array
CDeclare the service in the main.ts file
DUse the service without importing the module
If you import a shared module in multiple modules, what happens to its providers?
AThey are duplicated for each import
BThey are removed from the app
CThey are shared as single instances
DThey cause an error
Which decorator property lists modules that this module depends on?
Aexports
Bimports
Cproviders
Dcontrollers
What is the main benefit of using shared modules?
ATo reduce code duplication and reuse services
BTo increase app size
CTo create multiple instances of services
DTo avoid using providers
If a shared module imports another module, do the imported module's exports become available to modules importing the shared module?
AYes, automatically
BNo, only inside the shared module
COnly if the imported module is global
DOnly if the shared module re-exports them
Explain how to create and use a shared module in NestJS.
Think about how to share services across modules without rewriting them.
You got /4 concepts.
    Describe the difference between 'imports' and 'exports' in a NestJS module and why both are important.
    Consider how modules connect and share code.
    You got /4 concepts.