A progressive Node.js framework for building efficient and scalable server-side applications, heavily inspired by Angular.
Nest framework TypeScript starter repository.
$ npm install
# development
$ npm run start
# watch mode
$ npm run start:dev
# production mode
$ npm run start:prod
# unit tests
$ npm run test
# e2e tests
$ npm run test:e2e
# test coverage
$ npm run test:cov
nest g mi Logger
- AppModule implements NestModule
export class AppModule implements NestModule {
configure(consumer: MiddlewareConsumer) {
consumer .apply(LoggerMiddleware) .forRoutes('cats';
}
}
- Use Globale Middleware main.ts: app.use(logger)
- ValidationPipe 必须先安装 class-validator and class-transformer
- Use Global Pipe
Request payloads 使用 class 定义
使用 interface 定义
@Get @Post @Redirect @HttpCode @Header @Param @Body return Promise
ORM(Object Relational Mapper)
- install dependencies
npm install --save @nestjs/typeorm typeorm mysql
- import the TypeOrmModule into the root AppModule
import { TypeOrmModule } from '@nestjs/typeorm';
@Module({
imports: [
TypeOrmModule.forRoot({
type: 'mysql',
host: 'localhost',
port: 3306,
username: 'root',
password: 'root',
database: 'test',
entities: [],
synchronize: true,
}),
],
})
或者将数据库配置放到 ormconfig.json 中
$ npm install --save @nestjs/passport passport passport-local
$ npm install --save-dev @types/passport-local
- Helmet
- CORS
- CSFR
- Rate Limiting
Env ConfigurationSecurityGraphQL- OpenAPI (Swagger)