nest-cli
NestJS CLI 是一個命令行工具,讓開發者可以輕鬆創建、管理和開發 NestJS 應用程式。以下是其基本使用方法:
安裝 NestJS CLI
-
安裝 NestJS CLI:
你可以使用 npm(Node.js 套件管理器)來安裝 NestJS CLI。在終端機中輸入以下的指令:
npm i -g @nestjs/cli -
創建一個新的 NestJS 應用程式:
使用以下命令創建一個新的 NestJS 應用程式,其中
my-nest-app是你的應用程式名稱:nest new my-nest-app程式會提示你選擇一個套件管理器( 例如 npm 或 yarn),然後 CLI 會自動安裝所有必要的依賴並創建一個新的 NestJS 應用程式。
-
運行 NestJS 應用程式:
切換到你的應用程式目錄,然後使用以下命令運行你的應用程式:
cd my-nest-app
npm run start你的應用程式現在應該在
http://localhost:3000運行。 -
創建模組、控制器和服務:
通用的使用方式
# generate|g [options] <schematic> [name] [path] Generate a Nest element.
nest g [options] <schematic> [name] [path]
| name | alias | description |
|---|---|---|
| application | application | Generate a new application workspace |
| class | cl | Generate a new class |
| configuration | config | Generate a CLI configuration file |
| controller | co | Generate a controller declaration |
| decorator | d | Generate a custom decorator |
| filter | f | Generate a filter declaration |
| gateway | ga | Generate a gateway declaration |
| guard | gu | Generate a guard declaration |
| interceptor | itc | Generate an interceptor declaration |
| interface | itf | Generate an interface |
| library | lib | Generate a new library within a monorepo |
| middleware | mi | Generate a middleware declaration |
| module | mo | Generate a module declaration |
| pipe | pi | Generate a pipe declaration |
| provider | pr | Generate a provider declaration |
| resolver | r | Generate a GraphQL resolver declaration |
| resource | res | Generate a new CRUD resource |
| service | s | Generate a service declaration |
| sub-app | app | Generate a new application within a monorepo |
做用 resource 的時候可以直接建立 CRUD 的 file 出來 CRUD generator | NestJS - A progressive Node.js framework
IDE 套件管理器
- 安裝
NestJS Snippets套件
| Snippet | Prefix | Purpose |
|---|---|---|
| Nest Controller | n-controller | NestJS Controller |
| Nest v4 Middleware | n-v4-middleware | NestJS Middleware Version 4 |
| Nest v4 Module | n-v4-module | NestJS Module v4 |
| Nest Root Module | n-module-root | NestJS Root Module |
| Nest NestModule | n-module-nest | NestJS Module Implementing NestModule |
| Nest Mongoose Service | n-mongoose-service | NestJS Service for Mongoose |
| Nest Mongoose Interface | n-mongoose-interface | NestJS Interface for mongoose |
| Nest Unit Test | n-test | NestJS Unit Test |
| Nest Service Unit Test | n-test-service | NestJS Service Unit Test |
| Nest Sequelize Entity | n-sequelize-entity | NestJS Sequelize Entity |
| Nest Sequelize Provider | n-sequelize-provider | NestJS Sequelize Provider |
| Nest Sequelize Database Provider | n-sequelize-database-provider | NestJS Sequelize Provider |
| Nest Interceptor | n-interceptor | NestJS Interceptor |
| Nest Guard | n-guard | NestJS Guard |
| Nest Provider | n-provider | NestJS Provider |
| Nest Module | n-module | NestJS Module |
| Nest Global Module | n-module-global | NestJS Global Module |
| Nest Middleware | n-middleware | NestJS Middleware |
| Nest Pipe | n-pipe | NestJS Pipe |
| Nest TypeORM Entity | n-typeorm-entity | NestJS TypeORM Entity |
| Nest TypeORM Repository | n-typeorm-repository | NestJS TypeORM Repository |