Challenge - 5 Problems
NestJS Module Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What does this NestJS module output when imported?
Consider this NestJS module definition. What will be the value of
exports metadata after compilation?NestJS
import { Module } from '@nestjs/common'; import { ServiceA } from './serviceA'; @Module({ providers: [ServiceA], exports: [ServiceA], }) export class MyModule {}
Attempts:
2 left
💡 Hint
Look at what is explicitly listed in the exports array inside the @Module decorator.
✗ Incorrect
The exports metadata array contains only what is explicitly exported. Here, only ServiceA is exported, so the exports array is [ServiceA].
📝 Syntax
intermediate2:00remaining
Which option correctly defines a NestJS module with imports and controllers?
Select the code snippet that correctly uses the @Module decorator with imports and controllers arrays.
Attempts:
2 left
💡 Hint
Remember that imports and controllers expect arrays, not single values or objects.
✗ Incorrect
The @Module decorator expects arrays for imports and controllers. Option B correctly uses arrays. Options B, C, and D use invalid types causing syntax or runtime errors.
🔧 Debug
advanced2:00remaining
Why does this NestJS module fail to provide ServiceB to other modules?
Given this module, why can't other modules inject ServiceB?
NestJS
import { Module } from '@nestjs/common'; import { ServiceB } from './serviceB'; @Module({ providers: [ServiceB], }) export class FeatureModule {}
Attempts:
2 left
💡 Hint
Think about how NestJS shares providers between modules.
✗ Incorrect
Providers must be exported explicitly to be available for injection in other modules. Here, ServiceB is only provided but not exported, so other modules cannot inject it.
🧠 Conceptual
advanced2:00remaining
What is the role of the 'imports' array in the @Module decorator?
Choose the best description of what the 'imports' array does in a NestJS module.
Attempts:
2 left
💡 Hint
Think about how modules share providers in NestJS.
✗ Incorrect
The imports array allows a module to use providers exported by other modules. Controllers and providers are declared separately.
❓ state_output
expert2:00remaining
What is the value of 'exports' metadata after this module is compiled?
Analyze this NestJS module and determine the final 'exports' array value.
NestJS
import { Module } from '@nestjs/common'; import { ServiceX } from './serviceX'; import { ServiceY } from './serviceY'; @Module({ providers: [ServiceX, ServiceY], exports: [ServiceX], }) export class SharedModule {}
Attempts:
2 left
💡 Hint
Only what is listed in exports is shared outside the module.
✗ Incorrect
Even though both services are providers, only ServiceX is exported and thus available to other modules.