Questions
11 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?
11 / 25

What does the @Global() decorator do and how does it change module behaviour in NestJS?

@Global() registers the module's exported providers into the global DI scope. Any module in the application can inject those providers without listing the module in its own imports array. The global module must still be imported once — typically in AppModule — to be registered.

Global module registration and usage
Important rules for @Global():
  1. 1

    The module must still be imported once — usually in AppModule — to be registered in the container.

  2. 2

    After registration, its exports are available to every module without explicit imports.

  3. 3

    Only providers listed in exports are available globally — providers not exported remain private.

  4. 4

    Use @Global() sparingly — it hides dependencies and makes modules harder to test in isolation.

Difficulty: 5/10
Topics: global providers, module scope, dependency injection

Scenario Questions

0-2 years experience
  1. 1

    You need a ConfigService available in many feature modules without importing ConfigModule everywhere. How would you set it up using @Global()?

  2. 2

    If you add @Global() to a module but forget to export a provider, what will happen when another module tries to inject it?

2-5 years experience
  1. 1

    During a sprint you refactor a shared LoggerModule to be global. After the change, a feature module that previously imported LoggerModule starts throwing a circular dependency error. Why might that happen?

  2. 2

    You notice that a unit test for a controller fails because a globally provided AuthService is not mocked. How would you adjust the test setup to handle the global provider?

5-8 years experience
  1. 1

    Your team is scaling a microservice architecture and wants to avoid importing common utility modules in each NestJS microservice. Discuss the trade‑offs of making those modules global versus using a shared library.

  2. 2

    A performance audit shows that a globally scoped provider is instantiated multiple times unexpectedly. Explain how NestJS handles provider scope with @Global() and how you would fix the issue.

8+ years experience
  1. 1

    Looking ahead, you need to migrate several legacy NestJS applications into a monorepo. Some of them rely on global modules. How would you design a strategy to manage global providers to keep the monorepo maintainable and avoid hidden coupling?

  2. 2

    Your organization wants to enforce a policy that only certain core services can be global. Propose an architectural guideline and tooling approach to audit and enforce correct usage of @Global() across many teams.

Follow-up Questions

  • What are the main downsides of making a module global?
  • Can you override a global provider in a specific module, and how?
  • How does @Global() affect unit testing of individual modules?