# nestJS-development-template **Repository Path**: lidajing/nest-js-development-template ## Basic Information - **Project Name**: nestJS-development-template - **Description**: nestJS开发接口模板配置mysql数据库,接口文档swagger,前端静态资源放置目录,全局异常拦截,统一响应体格式,本地热更新,winston日志打印 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2022-11-08 - **Last Updated**: 2023-11-29 ## Categories & Tags **Categories**: Uncategorized **Tags**: Nestjs ## README # nestJS环境搭建基础模板 ## 静态资源部署配置 ```shell http://localhost:3000/ant-pro/ ``` ## 接口文档`swagger` ```shell http://localhost:3000/api/doc ``` ## 全局异常拦截 `app.useGlobalInterceptors(new TransformInterceptor());` ## 设置统一响应体格式 `app.useGlobalFilters(new AllExceptionsFilter());` ## `typeorm`和`mysql`数据库配置 ```ts // 数据库连接 TypeOrmModule.forRoot({ type: 'mysql', host: 'localhost', // port: 3306, username: 'root', password: '12345678', database: 'antpro', autoLoadEntities: true, synchronize: true, //实体与数据表进行对应,不创建数据库也会自动生成 }) ``` ## 本地运行项目开启热更新 ```shell npm run start:hotdev ``` ## 服务器部署运行 ```shell npm run start:prod ``` ## 生成一个CRUD ```bash # 执行命令选择`REST API` $ nest g resource menu ``` ## 日志框架`winston` ## 目录结构 ```shell 📁nest-js-development-template ├─ 📄.env.production ├─ 📄LICENSE ├─ 📄webpack-hmr.config.js ├─ 📄nest-cli.json ├─ 📄README.md ├─ 📄yarn.lock ├─ 📄.gitignore ├─ 📄package-lock.json ├─ 📄package.json ├─ 📄tsconfig.build.json ├─ 📄.prettierrc ├─ 📄.eslintrc.js ├─ 📄tsconfig.json ├─ 📄.env.development ├─ 📁test │ ├─ 📄app.e2e-spec.ts │ └─ 📄jest-e2e.json ├─ 📁dist ├─ 📁log │ ├─ 📄2023-11-28 15:59:20.log ├─ 📁ant-pro │ └─ 📄index.html ├─ 📁.idea │ ├─ 📄nest-js-development-template.iml │ ├─ 📄vcs.xml │ ├─ 📄.gitignore │ ├─ 📄workspace.xml │ ├─ 📄modules.xml │ ├─ 📁inspectionProfiles │ │ └─ 📄Project_Default.xml │ ├─ 📁codeStyles │ │ ├─ 📄Project.xml │ │ └─ 📄codeStyleConfig.xml │ └─ 📁jsLinters │ └─ 📄eslint.xml ├─ 📁src │ ├─ 📄main.ts │ ├─ 📄app.service.ts │ ├─ 📄doc.ts │ ├─ 📄app.module.ts │ ├─ 📄app.controller.spec.ts │ ├─ 📄app.controller.ts │ ├─ 📄mylogger.ts │ ├─ 📁winston │ │ ├─ 📄winston.module.ts │ │ └─ 📄mylogger.ts │ ├─ 📁user │ │ ├─ 📄user.module.ts │ │ ├─ 📄user.controller.ts │ │ ├─ 📄user.service.ts │ │ ├─ 📁dto │ │ └─ 📁entities │ └─ 📁common │ ├─ 📁interceptors │ └─ 📁exception ├─ 📁.git └─ 📁node_modules ```