npm install @nestjs/swagger swagger-ui-express -S
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { Logger, ValidationPipe } from '@nestjs/common';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
async function bootstrap() {
//引入日志模块
const app = await NestFactory.create(AppModule, {
logger: new Logger(),
});
//引入swagger模块
const options = new DocumentBuilder()
.setTitle('FS_ADMIN') // 标题
.setDescription('后台管理系统接口文档') // 描述
.setVersion('1.0') // 版本
.build();
const document = SwaggerModule.createDocument(app, options);
//配置swgger地址
SwaggerModule.setup('/qv_admin/api', app, document);
app.useGlobalPipes(new ValidationPipe());
await app.listen(3000);
}
bootstrap();
![](https://img-blog.csdnimg.cn/direct/8476c34002cf4b18acb19e662790a487.png)
http://localhost:3000/qv_admin/api
![](https://img-blog.csdnimg.cn/direct/b0f72e4784cb472180f3cc6debd9966f.png)
![](https://img-blog.csdnimg.cn/direct/d8e922cb147141a7a5d1d9f5c5c58abb.png)
![](https://img-blog.csdnimg.cn/direct/558849eedccb4e6aab9ac5a9206038dc.png)
![](https://img-blog.csdnimg.cn/direct/8daa04649eaf4fe09c890ad1dff17164.png)
![](https://img-blog.csdnimg.cn/direct/1d57e6cf29d54035bf230931acaf4ba1.png)