NestJS CLI
npm install -g @nestjs/cli
nest new [项目名]
npm run start:dev
当你将类型传递给 NestFactory.create() 方法时,如下例所示,app 对象将具有专用于该特定平台的方法。但请注意,除非你确实想要访问底层平台 API,否则不需要指定类型。
const app = await NestFactory.create<NestExpressApplication>(AppModule);
为了加快开发过程(构建速度加快 20 倍),你可以通过将 -b swc 标志传递给 start 脚本来使用 SWC 构建器。可以在 package.json
添加 "dev": "nest start --watch -b swc"
使用。
命令行 尽最大努力构建可靠的大规模开发工作流程。因此,生成的 Nest 项目预装了代码 linter 和格式化程序(分别为 eslint 和 prettier)。
# Lint and autofix with eslint
$ npm run lint
# Format with prettier
$ npm run format
CLI 常用命令
nest g co [模块名] # controller
nest g mo [模块名] # module
nest g s [模块名] # service
nest g res [模块名] # 一次生成以上
--flat # 不创建子目录
--no-spec #不创建测试文件
-d #不真实创建