Framework cheatsheet
NestJS 11 Cheatsheet
Generate and run NestJS apps, and write controllers, providers, DTO validation, guards, interceptors, configuration and tests.
CLI
- Install the Nest CLI — Install the command-line tool globally.
- Create a project — Scaffold a new application.
- Run in watch mode — Start the app and restart on file changes.
- Generate a full resource — Create a module, controller, service, DTOs and entity for a REST resource.
- Generate individual parts — Create a module, controller, service, guard, pipe or interceptor.
- Build for production — Compile to JavaScript in dist, then run it.
Controllers, providers and modules
- Write a controller — Decorators map methods to routes. Pipes such as ParseIntPipe convert and validate parameters.
- Write a provider (service) — @Injectable classes are created and injected by Nest. Throw built-in HTTP exceptions for errors.
- Wire things together in a module — A module declares its controllers and providers, and exports what other modules may use.
- Provide a value or factory — Register a value, class or factory under a token, for example to inject configuration or fakes.
- Load configuration — Make environment variables available everywhere, then inject ConfigService.
Validation, guards and interceptors
- Describe and validate a request body — Use class-validator decorators on a DTO class.
- Enable validation globally — Validate and transform every request body. whitelist removes properties the DTO doesn't declare.
- Protect routes with a guard — A guard decides whether a request may proceed. Throw or return false to deny it.
- Run code around handlers — An interceptor can log, transform responses or time requests.
- Customize error responses — A filter turns exceptions into the responses you want.
- Enable CORS — Allow browser apps on other origins to call the API.
- Generate OpenAPI docs — Serve an OpenAPI document and Swagger UI. Install @nestjs/swagger first.
Testing
- Unit test a service — Build a small testing module with only what the test needs.
- Replace a dependency with a fake — Provide a mock in place of the real provider.
- Test over HTTP — Start the app in memory and call it with supertest.
- Run the tests — Run unit tests, e2e tests and coverage.
Related cheatsheets
- Angular 22 cheatsheet — Angular CLI commands and standalone component, signals, template, routing, HTTP and forms snippets.
- Astro cheatsheet — Build fast content sites with Astro: components, layouts, routing, content collections, islands, endpoints and deployment.
- Django 6 cheatsheet — Create projects, run migrations, test and deploy Django apps, plus the ORM queries you use every day.
- .NET and ASP.NET Core 10 cheatsheet — The dotnet CLI for creating, building, testing and publishing projects, plus common ASP.NET Core and EF Core code.
- Express 5 cheatsheet — Build HTTP servers and APIs with Express 5 on Node.js.
- FastAPI 0.115 cheatsheet — Install, run, test and deploy FastAPI apps from the command line.