# nest-demo **Repository Path**: beatas/nest-demo ## Basic Information - **Project Name**: nest-demo - **Description**: 基于Nest.js的服务端开发模板,CURD上手即用 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2023-04-11 - **Last Updated**: 2023-04-11 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README

Nest Logo

[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456 [circleci-url]: https://circleci.com/gh/nestjs/nest

A progressive Node.js framework for building efficient and scalable server-side applications.

NPM Version Package License NPM Downloads CircleCI Coverage Discord Backers on Open Collective Sponsors on Open Collective Support us

## Description [Nest](https://github.com/nestjs/nest) framework TypeScript starter repository. This is a server-side development template based on Nest.js ## Installation ```bash $ npm install ``` ## Running the app ```bash # development $ npm run start # hot update $ npm run start:hot # watch mode $ npm run start:dev # production mode $ npm run start:prod ``` ## Test ```bash # unit tests $ npm run test # e2e tests $ npm run test:e2e # test coverage $ npm run test:cov ``` ## Support Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support). ## Web框架 使用`Fastify`作为前端框架 ```bash # 安装对于nest的适配器@nestjs/platform-fastify $ npm install @nestjs/platform-fastify ``` ## 版本配置 ```ts // main.ts 启用配置 app.enableVersioning({ type: VersioningType.URI, }); ``` 在相关的请求使用`@Version('1')`装饰符设置版本 ## 全局返回参数设置 `src/common/interceptors/transform.interceptor.ts` ```ts import { Injectable, NestInterceptor, ExecutionContext, CallHandler, } from '@nestjs/common'; import { Observable } from 'rxjs'; import { map } from 'rxjs/operators'; interface Response { data: T; } @Injectable() export class TransformInterceptor implements NestInterceptor> { intercept( context: ExecutionContext, next: CallHandler, ): Observable> { return next.handle().pipe( map((data) => ({ data, status: 0, extra: {}, message: 'success', success: true, })), ); } } ``` 在`main.ts`中添加全局拦截处理`useGlobalInterceptors` ```ts import { TransformInterceptor } from './common/interceptors/transform.interceptor'; // 统一响应体格式 app.useGlobalInterceptors(new TransformInterceptor()); ```