NestFactory Is a Factory: How Nest.js Bootstraps from a Single create() Call
Understanding that NestFactory.create() is a factory — not just a bootstrap ritual — clarifies why Nest applications scale: the framework's module system and DI container are built on the same encapsulation principle that keeps call sites decoupled from implementation changes.
The factory pattern isn't just a textbook abstraction in Nest.js — it's the literal entry point. NestFactory.create() takes a root module and returns a fully wired application instance, hiding Express or Fastify configuration, middleware setup, and dependency resolution behind a single call. This mirrors the classic factory example where a consumer asks for a product by type and receives a ready-to-use instance without knowing construction details.
Inside that root module, the @Module decorator acts as a manifest, declaring which controllers handle routing, which providers contain business logic, and which external modules are needed. Nest's IoC container then reads TypeScript metadata emitted at compile time to resolve constructor parameters and inject dependencies automatically — no manual wiring required.
The @Controller, @Injectable, and @Module decorators are not the classic runtime decorator pattern; they are TypeScript decorators that attach metadata at class definition time. The framework reads this metadata at startup to build the route map and dependency graph. True runtime decoration in Nest appears in guards and interceptors, which wrap request handlers dynamically.
The article's Mixue Ice Cream & Tea analogy is unusually effective because it maps directly to NestFactory.create() rather than stopping at a generic factory example — the consumer, the factory method, and the returned product all have exact framework counterparts.
Nest's choice to make the root module the single argument to create() means the entire application topology is declared in one module tree, which makes static analysis and code generation possible in ways that imperative wiring would not.
Calling TypeScript decorators 'the decorator pattern' is a common misconception; the article correctly distinguishes metadata decorators from runtime wrappers, but many Nest tutorials conflate the two, leading to confusion about when code actually executes.