The Nest CLI

Generate, Build & Run From One Tool

The Nest CLI

The Nest CLI is more than a scaffolder — it generates resources, builds for production, and runs the dev server.

4 min read Level 1/5 #nestjs#cli#tooling
What you'll learn
  • Generate modules, controllers, and services with `nest g`
  • Use `nest start --watch` for development
  • Use `nest build` for a production bundle

nest new was just the start. The same CLI generates files, builds, and runs your app. Learning its commands will save you hours of boilerplate.

Generating Building Blocks

The generate command (alias g) creates a file plus updates the surrounding module to register it.

nest g module users          # creates UsersModule
nest g controller users      # creates UsersController, adds to module
nest g service users         # creates UsersService, adds to module

Each command updates users.module.ts for you — no manual import-and-add dance. Short aliases work too: nest g co for controller, nest g s for service, nest g mo for module.

The Resource Generator

For a full CRUD scaffold in one shot:

nest g resource posts

It prompts for a transport (REST, GraphQL, microservice, WebSockets) and whether to generate CRUD entry points. With REST + yes, you get a module, controller, service, DTOs, and an entity — all wired together.

Running the App

nest start            # one-off run
nest start --watch    # restarts on file change (same as npm run start:dev)
nest start --debug    # attach a Node inspector on port 9229

Building for Production

nest build

That writes compiled JavaScript to dist/. Run it in production with node dist/main. Add --webpack if you want a bundled output for faster cold starts (handy in serverless).

Inspecting What You Have

nest info       # framework + dep versions
nest --help     # full command list

nest info is the first thing to paste into a bug report.

Project Structure →