NestJS Logo

CLI command reference

nest new#

Creates a new (standard mode) Nest project.


$ nest new <name> [options]
$ nest n <name> [options]
Description#

Creates and initializes a new Nest project. The command prompts for any information you don't pass as an option: the project name, the package manager, the module system (ESM or CommonJS), and whether to set up NestJS Observe.

Hint In non-interactive environments, such as CI, pass the project name and --package-manager. The module system then defaults to ESM, and Observe is set up only if you pass --observe.
Hint Choosing ESM scaffolds an ESM-first project that uses Vitest for testing. Choosing CommonJS scaffolds the traditional layout, which uses Jest. Both variants use oxlint for linting.

The command:

  • Creates a folder with the given <name>
  • Populates the folder with configuration files
  • Creates subfolders for source code (/src) and end-to-end tests (/test)
  • Populates the subfolders with default files for application components and tests
  • If Observe was set up, offers to link the project to it once the dependencies are installed (in an interactive terminal only). Accepting runs npx @nestjs/observe link, which writes the app key and secret into .env - see Linking from the terminal
Arguments#
ArgumentDescription
<name>The name of the new project
Options#
OptionDescription
--directory [directory]Destination directory.
--dry-runReport the changes that would be made, without changing the filesystem.
Alias: -d
--skip-gitSkip git repository initialization.
Alias: -g
--skip-installSkip package installation.
Alias: -s
--skip-testsSkip generating test files for the new project.
Alias: -t
--package-manager [package-manager]Package manager to use: npm, yarn, pnpm, or bun. The package manager must be installed globally.
Alias: -p
--language [language]Programming language: TS (default) or JS. The value is case-insensitive, and typescript / javascript are also accepted.
Alias: -l
--collection [collectionName]Schematics collection to use. Pass the package name of an installed npm package that contains the schematic.
Alias: -c
--strictEnable TypeScript's strict mode (with strictPropertyInitialization disabled) in the generated tsconfig.json. Enabled by default, and there is no flag to disable it: to opt out, set "strict": false in tsconfig.json after generating the project.
--formatFormat generated files using Prettier.
--observe / --no-observeSet up the @nestjs/observe SDK, or skip it, without being prompted. Omit both to be prompted in an interactive terminal (the prompt defaults to yes). Without a terminal, Observe is not set up.

nest generate#

Generates and/or modifies files based on a schematic.


$ nest generate <schematic> <name> [options]
$ nest g <schematic> <name> [options]
Arguments#
ArgumentDescription
<schematic>The schematic or collection:schematic to generate. See the table below for the available schematics.
<name>The name of the generated component. If omitted, the schematic prompts for it.
Schematics#
NameAliasDescription
appGenerate a new application within a monorepo (converting a standard mode structure to a monorepo).
librarylibGenerate a new library within a monorepo (converting a standard mode structure to a monorepo).
classclGenerate a new class.
controllercoGenerate a controller declaration.
decoratordGenerate a custom decorator. As of v12, the generated decorator uses the Reflector.createDecorator() form.
filterfGenerate a filter declaration.
gatewaygaGenerate a gateway declaration.
guardguGenerate a guard declaration.
interfaceitfGenerate an interface.
interceptoritcGenerate an interceptor declaration.
middlewaremiGenerate a middleware declaration.
modulemoGenerate a module declaration.
pipepiGenerate a pipe declaration.
providerprGenerate a provider declaration.
resolverrGenerate a resolver declaration.
resourceresGenerate a new CRUD resource (TypeScript only). See the CRUD (resource) generator.
servicesGenerate a service declaration.
Options#
OptionDescription
--dry-runReport the changes that would be made, without changing the filesystem.
Alias: -d
--project [project]Project that the element should be added to.
Alias: -p
--flatDo not generate a folder for the element.
--no-flatGenerate a folder for the element.
--collection [collectionName]Schematics collection to use. Pass the package name of an installed npm package that contains the schematic.
Alias: -c
--specGenerate spec files (default).
--no-specSkip generating spec files.
--spec-file-suffix [suffix]Use a custom suffix for spec files.
--skip-importSkip importing the generated element into its closest module.
--formatFormat generated files using Prettier.
--type <type>(resource only) Transport layer: rest, graphql-code-first, graphql-schema-first, microservice, or ws.
--crud [value](resource only) Whether to generate CRUD entry points (true or false).

nest build#

Compiles an application or workspace into an output folder.

The build command is also responsible for:

  • mapping paths (if you use path aliases) via tsconfig-paths
  • annotating DTOs with OpenAPI decorators (if the @nestjs/swagger CLI plugin is enabled)
  • annotating DTOs with GraphQL decorators (if the @nestjs/graphql CLI plugin is enabled)

$ nest build [name...] [options]
Arguments#
ArgumentDescription
[name...]The name of the project to build. Pass several names to build several projects. If omitted, the default project is built.
Options#
OptionDescription
--path [path]Path to tsconfig file.
Alias -p
--config [path]Path to nest-cli configuration file.
Alias -c
--watchRun in watch mode (live-reload).
With the tsc compiler, you can type rs to restart the application (when the manualRestart option is set to true).
Alias -w
--builder [name]Builder to use for compilation (tsc, swc, or rspack).
Alias -b
--webpackDeprecated legacy flag for webpack-based compilation. Use --builder rspack or another explicit builder instead.
--webpackPath [path]Deprecated legacy path to a webpack configuration file. Use the configuration supported by your selected builder instead.
--rspackPath [path]Path to a Rspack configuration file.
--tscForce the use of tsc for compilation.
--watchAssetsWatch non-TS files (assets such as .graphql files). See Assets for more details.
--type-checkEnable type checking (when SWC is used).
--no-type-checkDisable type checking (when SWC is used).
--emit-declarationsEmit declaration files (.d.ts) when using the SWC builder.
--allBuild all projects in a monorepo.
--parallel [concurrency]Build projects in parallel (use with --all). Pass a positive integer to limit concurrency, or omit the value for unlimited concurrency.
--silentSuppress informational compiler logs.
--preserveWatchOutputKeep outdated console output in watch mode instead of clearing the screen. (tsc watch mode only)

nest start#

Compiles and runs an application (or the default project in a workspace).


$ nest start [name] [options]
Arguments#
ArgumentDescription
[name]The name of the project to run. If omitted, the default project runs.
Options#
OptionDescription
--path [path]Path to tsconfig file.
Alias -p
--config [path]Path to nest-cli configuration file.
Alias -c
--watchRun in watch mode (live-reload).
Alias -w
--builder [name]Builder to use for compilation (tsc, swc, or rspack).
Alias -b
--preserveWatchOutputKeep outdated console output in watch mode instead of clearing the screen. (tsc watch mode only)
--watchAssetsRun in watch mode (live-reload), watching non-TS files (assets). See Assets for more details.
--debug [hostport]Run in debug mode (with the --inspect flag).
Alias -d
--webpackDeprecated legacy flag for webpack-based compilation. Use --builder rspack or another explicit builder instead.
--webpackPath [path]Deprecated legacy path to a webpack configuration file. Use the configuration supported by your selected builder instead.
--rspackPath [path]Path to a Rspack configuration file.
--tscForce the use of tsc for compilation.
--type-checkEnable type checking (when SWC is used).
--no-type-checkDisable type checking (when SWC is used).
--emit-declarationsEmit declaration files (.d.ts) when using the SWC builder.
--silentSuppress informational compiler logs.
--sourceRoot [sourceRoot]Root of the source code (overrides the sourceRoot setting in nest-cli.json).
--entryFile [entryFile]Entry file to run (overrides the entryFile setting in nest-cli.json).
--exec [binary]Binary to run (default: node).
Alias -e
--no-shellDo not spawn child processes within a shell (see the Node.js child_process.spawn() documentation).
--env-file [path]Load environment variables from a file, relative to the current directory, and expose them to the application on process.env. Repeat the option to load several files. A file that doesn't exist is skipped, with a notice.
-- [key=value]Command-line arguments that the application can read from process.argv.

nest add#

Imports a library that has been packaged as a nest library, running its install schematic.


$ nest add <name> [options]
Arguments#
ArgumentDescription
<name>The name of the library to import.
Options#
OptionDescription
--dry-runReport the changes that would be made, without changing the filesystem.
Alias: -d
--skip-installSkip package installation.
Alias: -s
--project [project]Project that the library should be added to.
Alias: -p

nest upgrade#

Upgrades an existing project to the latest NestJS major version.


$ nest upgrade [options]
$ nest update [options]
Description#

Run from the root of a NestJS v11 project, nest upgrade updates your dependencies to v12 and applies the mechanical parts of the migration:

  • Refuses to run on Node.js releases that lack require(esm) (anything older than v20.19, or v22.x older than v22.12)
  • Bumps every recognized @nestjs/* package to its v12-compatible major (@nestjs/graphql, @nestjs/apollo, and @nestjs/mercurius go to v14), and reports any other @nestjs/* package it doesn't recognize so you can review it yourself
  • Bumps TypeScript to v6 (required by the v12 CLI and schematics), and raises engines.node in package.json to >=20.19.0 if it declares a lower floor
  • Migrates nest-cli.json off the deprecated webpack / webpackConfigPath options and onto --builder rspack, updating matching package.json scripts
  • Renames the GraphQL playground option to graphiql, switches subscriptions from subscriptions-transport-ws to graphql-ws, and swaps the packages accordingly
  • Replaces the legacy nats package with @nats-io/transport-node / @nats-io/nats-core and rewrites nats imports
  • Moves library-specific @nestjs/config settings under validationOptions.libraryOptions and bumps Joi to v18 (the first release implementing Standard Schema)
  • Bumps Jest to v30 (and @types/jest / ts-jest to matching releases) where present, and warns that Jest can require() the ESM-only v12 packages only on Node.js v24.9+
  • Optionally installs and wires up @nestjs/observe. It prompts, unless you pass --observe or --no-observe
  • Checks tsconfig.json and tsconfig.build.json for settings that TypeScript 6 or the ESM-only packages no longer support, such as a legacy moduleResolution or a missing rootDir
  • Scans your sources and prints notes about behavior that changed but can't be migrated automatically, such as lifecycle hook ordering, refined pipe signatures, and structured logging params

The command finishes by installing the updated dependencies (unless --skip-install is passed) and printing a report of everything it changed, warned about, and left for you.

Warningnest upgrade only bumps the local@nestjs/cli dependency. Update a globally installed CLI yourself with npm i -g @nestjs/cli@latest, and do it before running the upgrade, because the command itself ships with the CLI.
Hint The command deliberately does not migrate your project to ESM, Vitest, or oxlint. Those are the defaults for newly generated v12 projects, but existing projects can adopt them on their own schedule. See the migration guide for the full picture.
Options#
OptionDescription
--dry-runReport the changes that would be made, without changing the filesystem.
Alias: -d
--skip-installSkip package installation.
Alias: -s
--observe / --no-observeSet up @nestjs/observe, or skip the setup, without being prompted. Omit both to be prompted in an interactive terminal (the prompt defaults to no). Without a terminal, Observe is not set up.
--tag [tag]Use an npm dist-tag (e.g., next) instead of the default version ranges.
Alias: -t
--collection [collectionName]Schematics collection to use. Pass the package name of an installed npm package that contains the schematic.
Alias: -c

nest deploy#

Deploys your application to the cloud, powered by Mau.


$ nest deploy [mau-options]
Description#

nest deploy is a thin wrapper around the Mau CLI. It locates the Mau binary and forwards every argument you pass to mau deploy, so any option Mau supports works here unchanged.

If Mau is not installed in your project, the command offers to add @nestjs/mau as a dev dependency and then continues. In a non-interactive environment (e.g., CI), the command fails instead of prompting, so install Mau explicitly first:


$ npm install --save-dev @nestjs/mau

Once Mau starts, it owns the terminal, so its output and prompts reach you directly. See the Deployment chapter for what Mau does and how to configure it.

nest info#

Displays information about installed Nest packages and other useful system information. For example:


$ nest info

 _   _             _      ___  _____  _____  _     _____
| \ | |           | |    |_  |/  ___|/  __ \| |   |_   _|
|  \| |  ___  ___ | |_     | |\ `--. | /  \/| |     | |
| . ` | / _ \/ __|| __|    | | `--. \| |    | |     | |
| |\  ||  __/\__ \| |_ /\__/ //\__/ /| \__/\| |_____| |_
\_| \_/ \___||___/ \__|\____/ \____/  \____/\_____/\___/

[System Information]
OS Version     : macOS Sequoia 24.6.0
NodeJS Version : v22.12.0
NPM Version    : 10.9.0

[Nest CLI]
Nest CLI Version : 12.0.3

[Nest Platform Information]
platform-express version : 12.0.4
schematics version       : 12.0.4
testing version          : 12.0.4
common version           : 12.0.4
core version             : 12.0.4
cli version              : 12.0.3
Edit on GitHub

Support us

Nest is an MIT-licensed open source project. It can grow thanks to the support of these awesome people. If you'd like to join them, please read more here.

Principal Sponsors

SerpApi LogoTrilon LogoMojam Logo

Sponsors / Partners

Become a sponsor