NestJS is a progressive, open-source Node.js framework for building efficient, reliable, and scalable server-side applications, released under an MIT License. It leverages TypeScript extensively, combining elements of Object-Oriented Programming (OOP), Functional Programming (FP), and Functional Reactive Programming (FRP) to provide a structured and opinionated development experience. Built on top of robust HTTP server frameworks like Express (default) and Fastify, it provides an out-of-the-box application architecture that helps developers create highly testable, loosely coupled, and easily maintainable applications. The current stable version is 11.1.19, with regular releases bringing new features, bug fixes, and performance enhancements. Key differentiators include its strong adherence to Angular-inspired modularity, dependency injection system, and a rich ecosystem for various application types like REST APIs, GraphQL APIs, and microservices.
npm install nestjsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates a basic NestJS application with a service, controller, and module, showcasing dependency injection and routing. It creates a simple CRUD API for 'items', listening on port 3000.
Upgrade your Node.js environment to version 16 or newer. Update your package.json `engines` field.
Install `@nestjs/cache-manager` and `cache-manager` packages (`npm i @nestjs/cache-manager cache-manager`). Update imports from `@nestjs/common` to `@nestjs/cache-manager` for `CacheModule`.
Ensure your project uses TypeScript v4.8 or higher. Update your `typescript` dependency in `package.json`.
Review Express v5 migration guides, specifically regarding route syntax. Wildcards now require names (e.g., `/*splat` instead of `/*`), and optional segments use braces (`/:file{.:ext}`).Use `forwardRef()` for modules or services when a circular dependency is unavoidable. Refactor your application design to reduce coupling if possible.
Always decorate services with `@Injectable()` and ensure they are listed in the `providers` array of their respective module. If the service is used in another module, it must also be in the `exports` array of its defining module and the `imports` array of the consuming module.
1. Ensure the dependency class is decorated with `@Injectable()`. 2. Add the dependency to the `providers` array of the current module. 3. If the dependency is from another module, ensure that module exports the dependency, and the current module imports that module.
Use `forwardRef(() => MyModule)` when importing modules or `forwardRef(() => MyService)` when injecting providers in a constructor to break the circular dependency. Consider refactoring to reduce tight coupling.
Ensure your `tsconfig.json` `module` option is set to `CommonJS` for Node.js environments. For ESM-only dependencies, you might need to configure your build tool (e.g., Webpack, SWC) to transpile them correctly, or configure Node.js to run in ESM mode (which requires specific NestJS setup). NestJS 10+ targets ES2021 by default.
Verify that `AppModule` is correctly imported in `main.ts` (e.g., `import { AppModule } from './app.module';`) and that `AppModule` class is `exported` from its file.