Lazy-loading Modules — Fundamentals · NestJS

Keep a module out of the startup graph and load it with LazyModuleLoader the first time a request needs it, then reuse it from the cache.

What you will learn

Read the theory for Lazy-loading Modules

All Fundamentals lessons

All NestJS courses

loading types…

What you'll learn

  • Load a module on demand with LazyModuleLoader and a dynamic import(), and take providers from the module reference it returns
  • Explain what the cache does on the second load, and read the console to see when the module was initialised
  • List what a lazily loaded module cannot contain: controllers, lifecycle hooks, global providers