Skip to content

NestJS Cheat Sheet

A single-page NestJS reference for decorators, module metadata, request pipeline pieces, and CLI commands used throughout this course.

How to Use This Cheat Sheet

Use the tables below as a lookup while building. Each entry maps to deeper lessons earlier in the course.

nest g resource cats
# module + controller + service + DTO stubs

The Nest CLI remains the fastest way to scaffold consistent feature files.

Request Pipeline Order

middleware -> guards -> interceptors(pre) -> pipes -> handler -> interceptors(post) -> filters(on error)
  • Controllers map HTTP; services hold logic; modules wire DI.
  • Pipes validate/transform; guards authorize; interceptors wrap; filters format errors.
  • Config and secrets come from ConfigModule.
  • Test with TestingModule and Supertest.

Decorator Quick Reference

Most-used Nest decorators.

Decorator Purpose
@Module() Declare module metadata
@Controller() HTTP controller
@Injectable() Provider participating in DI
@Get/Post/Patch/Delete() Route handlers
@Body/@Param/@Query() Input extraction
@UseGuards/@UsePipes/@UseInterceptors/@UseFilters() Attach pipeline pieces

Module Metadata Fields

Field Meaning
imports Other modules whose exported providers you need
controllers HTTP/GraphQL controllers/resolvers registered here
providers Injectable classes owned by this module
exports Providers shared with importing modules

CLI Commands

Command Purpose
nest new Scaffold project
nest g module|controller|service Generate building blocks
nest g resource CRUD resource scaffold
nest build Compile to dist
nest start --watch Dev watch mode

Common Exceptions

Class Status
BadRequestException 400
UnauthorizedException 401
ForbiddenException 403
NotFoundException 404
ConflictException 409

Common Mistakes

  • Using the cheat sheet without understanding trade-offs behind each API.
  • Copying snippets with secrets still hard-coded.

Key Takeaways

  • This sheet compresses Nest decorators, module fields, pipeline order, and CLI commands.
  • Use it for recall, then return to deeper lessons when needed.
  • Pipeline order explains many surprising bugs.

Pro Tip

Pin this page and the official Nest docs side by side—cheat sheets help memory; docs settle version-specific details.