The Nest CLI
The Nest CLI scaffolds projects and generates modules, controllers, and services with a single command.
Syntax
nest generate <schematic> <name>The Nest CLI is a command-line tool that scaffolds and maintains Nest applications. It is the fastest way to start and keeps your files consistent.
Common commands
nest new project-name- create a new application.nest generate module users- create a module (short:nest g mo users).nest generate controller users- create a controller.nest generate service users- create a service.nest generate resource users- generate a full CRUD resource at once.
Generators automatically update the surrounding module, so a generated service is registered for you.
Example
# Install the CLI globally
npm install -g @nestjs/cli
# Create a new project
nest new my-app
# Generate building blocks inside it
nest generate module users
nest generate controller users
nest generate service usersWhen to use it
- A developer runs `nest generate module orders` to scaffold a new Orders feature folder with boilerplate in under a second.
- A CI pipeline uses `nest build` to compile TypeScript and produce a dist/ folder ready for deployment without a separate tsc step.
- A team lead uses `nest generate resource products` to create a complete CRUD scaffold (module, controller, service, DTOs) for a new entity.
More examples
Scaffold a new project
Creates a complete project skeleton with tsconfig, main.ts, app module, and package.json in one command.
nest new my-api --package-manager npmGenerate a CRUD resource
Generates an entire CRUD resource including DTOs and entity stubs with a single CLI command.
nest generate resource products
# Prompts: REST API, generate CRUD? yes
# Creates: products.module.ts, products.controller.ts,
# products.service.ts, dto/, entities/Generate individual artifacts
Shows how to generate a module, controller (without test file), and service individually for fine-grained control.
nest g module orders
nest g controller orders --no-spec
nest g service orders
Discussion