The information in this guide is of an educational nature, it is mainly oriented to students and developers who start with NestJs, this compilation has been selected thinking about the necessary aspects for the basic and intermediate level courses, so it does not cover in depth each one of the mentioned aspects, only covers the most common characteristics in them.
If you want to go into more details, please check the CLI Command Reference at https://docs.nestjs.com/cli/overview
nest --version
nest -v
npm install -g @nestjs/cli
npm install -g @nestjs/cli@latest
npm install -g @nestjs/cli@version
npm uninstall -g @nestjs/cli
npm cache clean --force
nest --help
nest -h
nest <command> --help
nest [command] [args] [options]
- Most commands, and some options, have aliases.
- Arguments are not prefixed.
- Option names are prefixed with a double dash (--) characters.
- Option aliases are prefixed with a single dash (-) character.
Example:
nest build my-app -c production
nest build my-app --configuration production
nest b my-app -c production
nest b my-app --configuration production
nest new projectName
nest n projectName
Displays information about installed nest packages and other helpful system info.
nest info
nest i
Builds and serves your application, rebuilding on file changes.
nest start
nest start projectName
# Run in watch mode (live-reload).
nest start -w
nest start --watch
Compiles an application or library into an output directory at the given output path.
nest build
nest b
nest build projectName
NestJs does not include this functionality as part of the CLI, but we can execute it through NPM, since NestJs uses Lint, it is possible to see that the corresponding script is added to the package.json
npm lint
npm lint projectName
NestJs does not include this functionality as part of the CLI, but we can execute it through NPM, since NestJs uses Jest, it is possible to see that the corresponding script is added to the package.json
npm test
npm test projectName
Generate command in NestJs CLI is one of the building blocks of NestJs applications. It makes use of templates called schemas, which make it easy to create different elements quickly and safely.
nest generate <schematic>
nest g <schematic>
nest generate class [name]
nest generate cl [name]
nest g class [name]
nest g cl [name]
# Do not create "spec.ts" test files for the new class.
nest generate class [name] --no-spec
nest generate controller [name]
nest generate co [name]
nest g controller [name]
nest g co [name]
# Do not create "spec.ts" test files for the new controller.
nest generate controller [name] --no-spec
nest generate decorator [name]
nest generate d [name]
nest g decorator [name]
nest g d [name]
nest generate filter [name]
nest generate f [name]
nest g filter [name]
nest g f [name]
nest generate guard [name]
nest generate gu [name]
nest g guard [name]
nest g gu [name]
nest generate interceptor [name]
nest generate itc [name]
nest g interceptor [name]
nest g itc [name]
nest generate interface [name]
nest generate itf [name]
nest g interface [name]
nest g itf [name]
nest generate module [name]
nest generate mo [name]
nest g module [name]
nest g mo [name]
nest generate pipe [name]
nest generate pi [name]
nest g pipe [name]
nest g pi [name]
# Do not create "spec.ts" test files for the new pipe.
nest generate pipe [name] --no-spec
Generate a new CRUD resource that contains all the NestJS building blocks (module, service, controller classes) but also an entity class, DTO classes as well as the testing (.spec) files.
nest generate resource [name]
nest generate res [name]
nest g resource [name]
nest g res [name]
# Do not create "spec.ts" test files for the new resource.
nest generate resource [name] --no-spec
nest generate service [name]
nest generate s [name]
nest g service [name]
nest g s [name]
# Do not create "spec.ts" test files for the new service.
nest generate service [name] --no-spec
Fabian A. Becerra M. https://github.com/fabecerram
Code and documentation copyright 2019-2022 the authors. Code released under the MIT License.