Questions
4 of 25
1What are dynamic modules in NestJS and when do you use them?
2How would you lazy-load a module in NestJS to improve startup time?
3What are the four properties inside @Module() decorator?
4What is the difference between a shared module and a global module in NestJS?
5What is a NestJS module, and why is it needed?
6What is the difference between exports in a module and making a provider global with @Global()?
7What is the purpose of a module in NestJS and what does the @Module() decorator do?
8Are NestJS modules singletons? What does that mean practically?
9What is a feature module in NestJS and why should you use them instead of putting everything in AppModule?
10Can a feature module re-export an imported module in NestJS? When is this useful?
11What does the @Global() decorator do and how does it change module behaviour in NestJS?
12What are the risks of overusing @Global() modules in NestJS?
13How do you register a global module exactly once in NestJS and what happens if you register it twice?
14What is the naming convention for dynamic module static methods in NestJS and what does each name signal?
15How do you structure a feature module that has sub-features in NestJS?
16What is the difference between a shared module and a global module in NestJS?
17How can a dynamic module expose a forFeature() method that works alongside a forRoot() registration in NestJS?
18What is the module encapsulation rule in NestJS and why does it matter?
19What must the object returned by a dynamic module's static method always include in NestJS?
20What is the difference between imports and providers inside @Module()?
21What is a shared module in NestJS?
22When should you export a module vs export individual providers from a module in NestJS?
23What is a dynamic module in NestJS and how is it different from a static module?
24How do you implement forRootAsync() in a dynamic module so that options can be loaded asynchronously from ConfigService?
25How do you write a dynamic module that supports both sync (register) and async (registerAsync) configuration sharing the same internal providers?
04 / 25

What is the difference between a shared module and a global module in NestJS?

Difficulty: 4/10
module scope, dependency injection, global providers

A shared module exports providers so other modules can import it explicitly. A global module (decorated with @Global()) registers its exported providers application-wide so no explicit import is needed. Global modules should be registered only once in the root module and used sparingly to avoid hidden coupling.

A shared module is the standard pattern — it exports providers and must be imported explicitly by any module that wants to use them. A global module uses @Global() so its exports are available everywhere without needing to be imported.

Global module example
When to use each:
  1. 1

    Shared module — default choice; explicit imports keep dependencies traceable.

  2. 2

    Global module — use only for truly cross-cutting infrastructure like logging, config, or database connections.

  3. 3

    Global modules should be registered only once, in the root AppModule.

  4. 4

    Overusing @Global() leads to hidden coupling and makes modules harder to test in isolation.

Scenario Questions

0-2 years experience

  1. 1You need to reuse a LoggerService across two feature modules. How would you set it up using a shared module, and what would you have to do differently if you made the LoggerModule global?
  2. 2If you forget to add a provider to the exports array of a shared module, what runtime error would you see when another module tries to inject it?
  3. 3What happens when you import a module marked with @Global() into the root AppModule versus importing it into a feature module?

2-5 years experience

  1. 1During a sprint, a teammate added a new service to a shared module but didn't export it, causing a dependent module to fail. Walk me through how you'd debug and fix it.
  2. 2We have a configuration service needed only in a few modules. Would you choose a global module or a shared module for this, and why?
  3. 3Our application started throwing 'Nest cannot resolve dependencies' after we turned a shared module into a global one. What could be the cause?

5-8 years experience

  1. 1With dozens of feature modules, discuss the performance and maintainability implications of marking many modules as global versus keeping them shared.
  2. 2How would you design a plugin system where third‑party modules can register providers without polluting the global namespace? Relate this to shared vs global modules.
  3. 3If you need to lazy‑load a module that provides a heavy database connection, why might a shared module be preferable to a global module, and how would you implement it?

8+ years experience

  1. 1Our monorepo contains multiple NestJS microservices that share common utilities. Describe a strategy for managing shared code that avoids overusing global modules while keeping versioning and deployment simple.
  2. 2When migrating a legacy NestJS codebase that heavily relies on @Global() modules, what steps would you take to refactor toward shared modules to improve testability and isolation?
  3. 3Consider a scenario where a global module registers a provider that holds mutable state. What architectural risks does this introduce across teams, and how would you mitigate them?

Follow-up Questions

  • What are the main downsides of using a global module in a large codebase?
  • How does NestJS resolve provider scope when a provider is declared in both a shared and a global module?
  • Can you describe a situation where a global module caused a circular dependency and how you would break it?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.