### Install NestJS CLI Globally Source: https://context7.com/nestjs/nest-cli/llms.txt Install the NestJS CLI globally using npm, yarn, or pnpm to access the 'nest' command. Verify the installation by checking the version. ```bash npm install -g @nestjs/cli ``` ```bash yarn global add @nestjs/cli ``` ```bash pnpm add -g @nestjs/cli ``` ```bash nest --version ``` -------------------------------- ### Install Nest CLI Globally Source: https://github.com/nestjs/nest-cli/blob/master/README.md Install the Nest CLI globally using npm. This command makes the `nest` command available system-wide. ```bash npm install -g @nestjs/cli ``` -------------------------------- ### Example Commit Message (Docs) Source: https://github.com/nestjs/nest-cli/blob/master/CONTRIBUTING.md An example of a commit message for documentation changes, following the specified format. ```git docs(changelog) update change log to beta.5 ``` -------------------------------- ### Start NestJS Application Source: https://context7.com/nestjs/nest-cli/llms.txt Starts the NestJS application. Use `--watch` for live reloading during development, `--debug` for debugging, `--builder` to specify a compiler like SWC or webpack, and `--entryFile` or `--sourceRoot` for custom configurations. ```bash nest start ``` ```bash nest start --watch ``` ```bash nest start -w ``` ```bash nest start --debug ``` ```bash nest start -d ``` ```bash nest start --debug 9229 ``` ```bash nest start --builder swc ``` ```bash nest start -b swc ``` ```bash nest start --builder swc --type-check ``` ```bash nest start --builder webpack ``` ```bash nest start admin-app ``` ```bash nest start --entryFile main ``` ```bash nest start --sourceRoot src ``` ```bash nest start --exec ts-node ``` ```bash nest start -e ts-node ``` ```bash nest start --env-file .env ``` ```bash nest start --env-file .env --env-file .env.local ``` ```bash nest start --no-shell ``` ```bash nest start --watch --watchAssets ``` ```bash nest start --watch --preserveWatchOutput ``` ```bash nest start -- --port 3001 --env production ``` -------------------------------- ### Example Commit Message (Fix) Source: https://github.com/nestjs/nest-cli/blob/master/CONTRIBUTING.md An example of a commit message for a bug fix, including a scope and a detailed body explaining the necessity of the change. ```git fix(@nestjs/core) need to depend on latest rxjs and zone.js The version in our package.json gets copied to the one we publish, and users need the latest of these. ``` -------------------------------- ### Add NestJS Libraries Source: https://context7.com/nestjs/nest-cli/llms.txt Use `nest add` to install and configure official NestJS packages and third-party libraries. You can specify versions, target specific projects in a monorepo, perform a dry run, or skip package installation. ```bash nest add @nestjs/config ``` ```bash nest add @nestjs/swagger ``` ```bash nest add @nestjs/typeorm ``` ```bash nest add @nestjs/mongoose ``` ```bash nest add @nestjs/graphql ``` ```bash nest add @nestjs/websockets ``` ```bash nest add @nestjs/microservices ``` ```bash nest add @nestjs/jwt ``` ```bash nest add @nestjs/passport ``` ```bash nest add @nestjs/schedule ``` ```bash nest add @nestjs/cache-manager ``` ```bash nest add @nestjs/event-emitter ``` ```bash nest add @nestjs/bull ``` ```bash nest add @nestjs/throttler ``` ```bash nest add @nestjs/terminus ``` ```bash nest add @nestjs/swagger@6 ``` ```bash nest add @nestjs/config --project admin-app ``` ```bash nest add @nestjs/swagger --dry-run ``` ```bash nest add @nestjs/swagger --skip-install ``` -------------------------------- ### Create New NestJS Application Source: https://context7.com/nestjs/nest-cli/llms.txt Create a new NestJS application with a default project structure. Options include specifying the package manager, directory, language (JavaScript/TypeScript), strict mode, skipping git initialization or package installation, performing a dry run, using custom schematics, or using a short alias. ```bash nest new my-project ``` ```bash nest new my-project --package-manager pnpm ``` ```bash nest new my-project --directory ./apps ``` ```bash nest new my-project --language javascript ``` ```bash nest new my-project --strict ``` ```bash nest new my-project --skip-git ``` ```bash nest new my-project --skip-install ``` ```bash nest new my-project --dry-run ``` ```bash nest new my-project --collection @nestjs/schematics ``` ```bash nest n my-project ``` -------------------------------- ### Configure SWC Builder in Nest CLI Source: https://context7.com/nestjs/nest-cli/llms.txt Use this configuration to enable SWC for faster builds. Specify SWC options like output directory and file extensions. ```json { "$schema": "https://json.schemastore.org/nest-cli", "collection": "@nestjs/schematics", "sourceRoot": "src", "compilerOptions": { "builder": { "type": "swc", "options": { "swcrcPath": ".swcrc", "outDir": "dist", "filenames": ["src"], "sync": false, "extensions": [".ts"], "copyFiles": false, "includeDotfiles": false, "quiet": false } }, "typeCheck": true } } ``` -------------------------------- ### Display NestJS Project Information Source: https://context7.com/nestjs/nest-cli/llms.txt The `nest info` command provides detailed system and NestJS project information, including CLI and package versions, with compatibility checks. Use `nest i` as a shorthand. ```bash nest info ``` ```bash nest i ``` -------------------------------- ### Nest CLI Configuration (`nest-cli.json`) Source: https://context7.com/nestjs/nest-cli/llms.txt The `nest-cli.json` file configures build, generation, and runtime options. It specifies the collection, source root, language, and compiler options, including asset watching and plugins. ```json { "$schema": "https://json.schemastore.org/nest-cli", "collection": "@nestjs/schematics", "sourceRoot": "src", "entryFile": "main", "language": "ts", "monorepo": false, "compilerOptions": { "builder": { "type": "tsc", "options": { "configPath": "tsconfig.build.json" } }, "assets": ["**/*.graphql", "**/*.json"], "watchAssets": true, "deleteOutDir": true, "plugins": [ { "name": "@nestjs/swagger", "options": { "classValidatorShim": true, "introspectComments": true } } ] }, "generateOptions": { "spec": true, "flat": false, "specFileSuffix": "spec" } } ``` -------------------------------- ### Build with Watch and Preserve Output Source: https://context7.com/nestjs/nest-cli/llms.txt Use the `nest build` command with the `--watch` flag to automatically recompile on file changes and `--preserveWatchOutput` to prevent the console from clearing between builds. ```bash nest build --watch --preserveWatchOutput ``` -------------------------------- ### Monorepo Configuration (`nest-cli.json`) Source: https://context7.com/nestjs/nest-cli/llms.txt Configure a monorepo structure in `nest-cli.json` by setting `"monorepo": true` and defining individual projects (applications and libraries) with their specific configurations, including source roots and compiler options. ```json { "$schema": "https://json.schemastore.org/nest-cli", "collection": "@nestjs/schematics", "sourceRoot": "apps/main-app/src", "monorepo": true, "root": "apps/main-app", "compilerOptions": { "builder": "swc", "deleteOutDir": true, "assets": ["**/*.graphql"], "watchAssets": true }, "projects": { "main-app": { "type": "application", "root": "apps/main-app", "entryFile": "main", "sourceRoot": "apps/main-app/src", "compilerOptions": { "tsConfigPath": "apps/main-app/tsconfig.app.json" } }, "admin-app": { "type": "application", "root": "apps/admin-app", "entryFile": "main", "sourceRoot": "apps/admin-app/src", "compilerOptions": { "tsConfigPath": "apps/admin-app/tsconfig.app.json" } }, "shared": { "type": "library", "root": "libs/shared", "entryFile": "index", "sourceRoot": "libs/shared/src", "compilerOptions": { "tsConfigPath": "libs/shared/tsconfig.lib.json" } } } } ``` -------------------------------- ### Configure Generate Options in Nest CLI Source: https://context7.com/nestjs/nest-cli/llms.txt Set default options for code generation, such as which files to generate for a resource and file naming conventions. ```json { "$schema": "https://json.schemastore.org/nest-cli", "collection": "@nestjs/schematics", "sourceRoot": "src", "generateOptions": { "spec": { "controller": true, "service": true, "guard": false, "interceptor": false, "filter": false, "pipe": false, "middleware": false, "gateway": false, "resolver": false }, "flat": false, "specFileSuffix": "spec", "baseDir": "" } } ``` -------------------------------- ### Generate NestJS Application Elements Source: https://context7.com/nestjs/nest-cli/llms.txt Generate various NestJS building blocks like controllers, services, modules, resources, guards, interceptors, pipes, filters, middleware, decorators, gateways, resolvers, interfaces, classes, libraries, and sub-applications. Options include generating without a spec file, using a flat structure, specifying a project or path, skipping automatic module imports, custom spec file suffixes, or performing a dry run. ```bash nest generate controller users nest g controller users ``` ```bash nest generate service users nest g service users ``` ```bash nest generate module users nest g module users ``` ```bash nest generate resource products nest g res products ``` ```bash nest generate guard auth nest g gu auth ``` ```bash nest generate interceptor logging nest g itc logging ``` ```bash nest generate pipe validation nest g pi validation ``` ```bash nest generate filter http-exception nest g f http-exception ``` ```bash nest generate middleware logger nest g mi logger ``` ```bash nest generate decorator roles nest g d roles ``` ```bash nest generate gateway events nest g ga events ``` ```bash nest generate resolver users nest g r users ``` ```bash nest generate interface user nest g itf user ``` ```bash nest generate class user.entity nest g cl user.entity ``` ```bash nest generate library shared nest g lib shared ``` ```bash nest generate sub-app admin nest g app admin ``` ```bash nest generate service users --no-spec ``` ```bash nest generate controller users --flat ``` ```bash nest generate service users --project admin-app ``` ```bash nest generate controller users src/modules/users ``` ```bash nest generate service users --skip-import ``` ```bash nest generate service users --spec-file-suffix test ``` ```bash nest generate controller users --dry-run ``` -------------------------------- ### Commit Changes with Git Source: https://github.com/nestjs/nest-cli/blob/master/CONTRIBUTING.md Use this command to commit your changes with a descriptive message. The -a flag automatically stages modified files. ```shell git commit -am "" ``` -------------------------------- ### Push Branch to GitHub Source: https://github.com/nestjs/nest-cli/blob/master/CONTRIBUTING.md Push your local branch to your GitHub repository to make it available for a pull request. The -u flag sets the upstream for future pushes. ```shell git push origin my-fix-branch ``` ```shell git push -u origin my-fix-branch ``` -------------------------------- ### Rebase and Force Push Updates Source: https://github.com/nestjs/nest-cli/blob/master/CONTRIBUTING.md After making updates based on review suggestions, rebase your branch onto the main branch and force push to update your pull request. ```shell git rebase master -i git push -f ``` -------------------------------- ### Configure Webpack Builder in Nest CLI Source: https://context7.com/nestjs/nest-cli/llms.txt Configure the Nest CLI to use Webpack for advanced bundling. This requires specifying a Webpack configuration file path. ```json { "$schema": "https://json.schemastore.org/nest-cli", "collection": "@nestjs/schematics", "sourceRoot": "src", "compilerOptions": { "builder": { "type": "webpack", "options": { "configPath": "webpack.config.js" } } } } ``` ```javascript // webpack.config.js module.exports = function(options, webpack) { return { ...options, plugins: [ ...options.plugins, new webpack.DefinePlugin({ 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV), }), ], externals: [], }; }; ``` -------------------------------- ### Build NestJS Application Source: https://context7.com/nestjs/nest-cli/llms.txt Compile the NestJS application for production using different builders (tsc, SWC, webpack) and options. Supports watch mode, type checking, custom configurations, monorepo builds, and watching non-TypeScript assets. ```bash nest build ``` ```bash nest build --watch nest build -w ``` ```bash nest build --builder swc nest build -b swc ``` ```bash nest build --builder swc --type-check ``` ```bash nest build --builder webpack ``` ```bash nest build --builder webpack --webpackPath ./webpack.config.js ``` ```bash nest build --path ./tsconfig.build.json nest build -p ./tsconfig.build.json ``` ```bash nest build --config ./nest-cli.custom.json nest build -c ./nest-cli.custom.json ``` ```bash nest build admin-app ``` ```bash nest build --all ``` ```bash nest build --watch --watchAssets ``` -------------------------------- ### Checkout Master Branch Source: https://github.com/nestjs/nest-cli/blob/master/CONTRIBUTING.md Switch to the master branch locally. The -f flag forces the checkout, discarding any uncommitted local changes. ```shell git checkout master -f ``` -------------------------------- ### Commit Message Header Format Source: https://github.com/nestjs/nest-cli/blob/master/CONTRIBUTING.md The standard format for commit message headers, including type, optional scope, and subject. Adhere to the 100-character limit for all lines. ```git ():