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

What is a NestJS module, and why is it needed?

A module is a class decorated with @Module() that acts as the organizational unit of a NestJS app. It groups related controllers, providers, and imports. Every app has at least one root module (AppModule). NestJS uses the module graph to wire up the DI container at startup.

A module is a class annotated with the @Module() decorator. NestJS uses the information provided by this decorator to organize the application structure and build the dependency injection container.

Key points about modules:
  1. 1

    Every NestJS app has at least one root module — AppModule.

  2. 2

    Modules encapsulate a closely related set of capabilities.

  3. 3

    The module graph is used by NestJS to resolve provider dependencies.

  4. 4

    Modules are singletons by default — the same instance is shared across the app.

Basic module example
Difficulty: 5/10
Topics: module organization, dependency injection, scoping

Scenario Questions

0-2 years experience
  1. 1

    If you need to add a new service for sending emails, how would you structure a NestJS module for it, and what steps are required to make the service available to other parts of the app?

  2. 2

    What happens if you forget to import a module that provides a controller you want to use in another module?

  3. 3

    Where would you place shared utility functions and how would you expose them through a module?

2-5 years experience
  1. 1

    We have a UsersModule and an AuthModule, but Auth needs the UsersService. How would you resolve this circular dependency using NestJS modules?

  2. 2

    After moving some providers into a new module, a previously working endpoint started returning 500 errors. Walk me through how you would debug the issue and what module‑related pitfalls you’d check.

  3. 3

    If you need to load a module only in a testing environment, what approaches does NestJS provide and what are the trade‑offs?

5-8 years experience
  1. 1

    Our monolith is growing and we plan to split it into several bounded‑context modules that will be loaded lazily. How would you design the module hierarchy to minimize startup time and keep DI performant?

  2. 2

    How would you share a cache service across multiple dynamically loaded modules without creating duplicate instances, and which module configuration patterns would you use?

  3. 3

    When integrating a third‑party library that requires global configuration, how would you decide between a global module and a scoped module, considering testability and future scaling?

8+ years experience
  1. 1

    We are migrating a legacy Express codebase to NestJS. How would you reorganize the existing code into NestJS modules to ensure clean separation of concerns while allowing incremental migration?

  2. 2

    Several teams need a common authentication module that must evolve independently. What architectural strategies would you employ to version and share this module without causing breaking changes for downstream services?

  3. 3

    If the company mandates that all modules expose only explicit public providers and avoid accidental leaks, how would you enforce this at the framework or CI level?

Follow-up Questions

  • How would you make a provider available across the entire application without importing its module everywhere?
  • What are the trade‑offs of using the @Global() decorator on a module?
  • Can you describe a strategy to test that a module correctly exports its intended providers?