# server_base **Repository Path**: hzqhxy/server_base ## Basic Information - **Project Name**: server_base - **Description**: 采用nest+ts+swagger+mongoDB - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-09-26 - **Last Updated**: 2024-09-26 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## Project setup 1. 安装nest cli ```bash $ npm i -g @nestjs/cli ``` > 如果有nest -v 命令,可以忽略上一步,则不需要安装; 2. 创建项目 ```bash $ nest new project-name ``` 3. 进入项目目录 ```bash $ cd project-name ``` 3. 安装依赖并打开vscode ```bash $ pnpm install $ code . ``` ## Compile and run the project ```bash # development $ pnpm run start # watch mode $ pnpm run start:dev # production mode $ pnpm run start:prod ``` ## 关联远程仓库 > 参考git部分 ## ESLint: Delete `␍`(prettier/prettier) 错误解决方案 ```js // .eslintrc.js { "rules": { "prettier/prettier": ["error", { "endOfLine": "auto" }] } } ``` ## swagger 1. 安装 ```bash pnpm add --save @nestjs/swagger fastify-swagger ``` 2. 配置 ```js // main.ts import { NestFactory } from '@nestjs/core'; import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'; import { AppModule } from './app.module'; async function bootstrap() { const app = await NestFactory.create(AppModule); const options = new DocumentBuilder() .setTitle('API文档') .setDescription('API文档') .setVersion('1.0') .addBearerAuth() .build(); const document = SwaggerModule.createDocument(app, options); SwaggerModule.setup('api', app, document); // 访问地址:http://localhost:3000/api await app.listen(3000); } bootstrap(); ```