Bird
Raised Fist0
NestJSframework~5 mins

Module re-exporting in NestJS - Cheat Sheet & Quick Revision

Choose your learning style10 modes available
Recall & Review
beginner
What is module re-exporting in NestJS?
Module re-exporting in NestJS means a module imports another module and then exports it again. This lets other modules access the imported module's providers without importing it directly.
Click to reveal answer
beginner
Why use module re-exporting in NestJS?
It helps organize code by grouping related modules. Other modules only import one module instead of many. This keeps imports clean and easier to manage.
Click to reveal answer
beginner
How do you re-export a module in NestJS?
In the @Module decorator, add the module you want to re-export to both the imports and exports arrays.
Click to reveal answer
intermediate
Example: If ModuleA imports ModuleB and exports ModuleB, what can ModuleC do?
ModuleC can import ModuleA and use providers from ModuleB without importing ModuleB directly.
Click to reveal answer
intermediate
What happens if you import a module but do not export it in NestJS?
The imported module's providers are available only inside the importing module. Other modules importing this module cannot access those providers.
Click to reveal answer
In NestJS, how do you make a module's providers available to other modules through re-exporting?
AUse a special decorator @ReExport
BOnly add the module to imports array
CAdd the module to both imports and exports arrays in @Module
DOnly add the module to exports array
What benefit does module re-exporting provide in NestJS?
AIt automatically generates services
BIt reduces the number of imports needed in other modules
CIt disables providers in the imported module
DIt merges two modules into one
If ModuleA imports ModuleB but does not export it, can ModuleC access ModuleB's providers by importing ModuleA?
AYes, always
BOnly if ModuleC also imports ModuleB
COnly if ModuleA uses global scope
DNo, because ModuleB is not re-exported
Which decorator property controls what a NestJS module shares with other modules?
Aexports
Bimports
Cproviders
Dcontrollers
Can a module re-export multiple modules in NestJS?
AYes, by listing them in imports and exports arrays
BNo, only one module can be re-exported
CYes, but only if they are controllers
DNo, re-exporting is not supported
Explain how module re-exporting works in NestJS and why it is useful.
Think about how one module can share another module's features with others.
You got /4 concepts.
    Describe the difference between importing a module and re-exporting a module in NestJS.
    Focus on what happens inside the module versus what is shared outside.
    You got /4 concepts.

      Practice

      (1/5)
      1. What is the main purpose of module re-exporting in NestJS?
      easy
      A. To share modules through another module for better organization
      B. To create multiple instances of the same module
      C. To prevent modules from being imported anywhere
      D. To automatically generate services inside a module

      Solution

      1. Step 1: Understand module re-exporting concept

        Module re-exporting allows one module to share its imported modules with other modules by re-exporting them.
      2. Step 2: Identify the purpose in NestJS

        This helps keep the app organized and makes modules easier to maintain by avoiding repeated imports.
      3. Final Answer:

        To share modules through another module for better organization -> Option A
      4. Quick Check:

        Module re-exporting = sharing modules [OK]
      Hint: Re-exporting means sharing modules via another module [OK]
      Common Mistakes:
      • Thinking re-exporting creates new module instances
      • Believing it blocks module imports
      • Confusing it with automatic service generation
      2. Which syntax correctly re-exports a module named SharedModule inside another module's decorator?
      easy
      A. @Module({ exports: [SharedModule] })
      B. @Module({ imports: [], exports: [SharedModule] })
      C. @Module({ imports: [SharedModule] })
      D. @Module({ imports: [SharedModule], exports: [SharedModule] })

      Solution

      1. Step 1: Recall NestJS module decorator structure

        To re-export a module, it must be both imported and exported in the module decorator.
      2. Step 2: Check each option

        The syntax with both imports: [SharedModule] and exports: [SharedModule] is correct. Syntaxes missing either array are incorrect.
      3. Final Answer:

        @Module({ imports: [SharedModule], exports: [SharedModule] }) -> Option D
      4. Quick Check:

        Import and export to re-export [OK]
      Hint: Re-export needs both imports and exports arrays [OK]
      Common Mistakes:
      • Only exporting without importing
      • Only importing without exporting
      • Leaving either array empty when re-exporting
      3. Given these modules, what will be the output of console.log(appModuleImports) if AppModule imports CoreModule which re-exports SharedModule?
      @Module({ imports: [SharedModule], exports: [SharedModule] })
      export class CoreModule {}
      
      @Module({ imports: [CoreModule] })
      export class AppModule {}
      Assuming appModuleImports is the list of modules available inside AppModule.
      medium
      A. [SharedModule]
      B. [CoreModule, SharedModule]
      C. [CoreModule]
      D. []

      Solution

      1. Step 1: Understand re-export effect on imports

        CoreModule imports and exports SharedModule, so any module importing CoreModule also gets SharedModule.
      2. Step 2: Analyze AppModule imports

        AppModule imports CoreModule, so it has access to both CoreModule and SharedModule.
      3. Final Answer:

        [CoreModule, SharedModule] -> Option B
      4. Quick Check:

        Re-exported modules appear in importing module imports [OK]
      Hint: Re-exported modules appear as if directly imported [OK]
      Common Mistakes:
      • Assuming only CoreModule is available
      • Thinking SharedModule is hidden
      • Ignoring exports array effect
      4. Identify the error in this module re-exporting code:
      @Module({
        imports: [SharedModule],
        exports: []
      })
      export class CoreModule {}
      medium
      A. SharedModule is imported but not exported, so it is not re-exported
      B. SharedModule should not be in imports when re-exporting
      C. exports array cannot be empty in any module
      D. CoreModule must import AppModule to re-export SharedModule

      Solution

      1. Step 1: Check imports and exports arrays

        SharedModule is imported but not exported, so CoreModule does not re-export it.
      2. Step 2: Understand re-export requirement

        To re-export a module, it must be listed in both imports and exports arrays.
      3. Final Answer:

        SharedModule is imported but not exported, so it is not re-exported -> Option A
      4. Quick Check:

        Re-export needs both imports and exports [OK]
      Hint: Exports must include imported modules to re-export [OK]
      Common Mistakes:
      • Leaving exports empty when re-exporting
      • Confusing imports-only as re-export
      • Thinking exports array is optional
      5. You have three modules: SharedModule, CoreModule, and FeatureModule. CoreModule imports and re-exports SharedModule. FeatureModule imports CoreModule. How can you modify FeatureModule to also re-export SharedModule without importing it directly?
      hard
      A. Add imports: [SharedModule] in FeatureModule
      B. Add exports: [SharedModule] in FeatureModule
      C. Add exports: [CoreModule] in @Module decorator of FeatureModule
      D. Add providers: [SharedModule] in FeatureModule

      Solution

      1. Step 1: Understand re-export chaining

        FeatureModule imports CoreModule, which re-exports SharedModule, so FeatureModule has access to SharedModule.
      2. Step 2: Re-export SharedModule via CoreModule

        To re-export SharedModule from FeatureModule without importing it directly, FeatureModule must export CoreModule.
      3. Final Answer:

        Add exports: [CoreModule] in @Module decorator of FeatureModule -> Option C
      4. Quick Check:

        Export imported module to re-export its exports [OK]
      Hint: Export imported module to re-export its exports [OK]
      Common Mistakes:
      • Trying to export SharedModule without importing it
      • Adding SharedModule to providers array
      • Importing SharedModule directly instead of re-exporting
      Recommended

      Ready to prove it?

      Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

      10 questions~5 mineasy hard