NestJS 微服务样板项目教程

NestJS 微服务样板项目教程

nestjs-boilerplate-microserviceNestjs Microservice boilerplate: apply DDD, CQRS, and Event Sourcing within an event driven architecture项目地址:https://gitcode.com/gh_mirrors/ne/nestjs-boilerplate-microservice

1. 项目的目录结构及介绍

nestjs-boilerplate-microservice/
├── src/
│   ├── application/
│   ├── domain/
│   ├── infrastructure/
│   ├── presentation/
│   ├── shared/
│   │   ├── constants/
│   │   ├── decorators/
│   │   ├── exceptions/
│   │   ├── filters/
│   │   ├── guards/
│   │   ├── interceptors/
│   │   ├── middleware/
│   │   ├── pipes/
│   │   ├── strategies/
│   │   ├── utils/
│   │   └── validators/
│   ├── tests/
│   └── main.ts
├── test/
│   └── initialization.ts
├── TRACING.md
├── tsconfig.build.json
└── tsconfig.json

目录结构介绍

  • src/application: 包含应用层代码,处理业务逻辑。
  • src/domain: 包含领域层代码,定义领域模型和业务规则。
  • src/infrastructure: 包含基础设施层代码,处理与外部系统的交互。
  • src/presentation: 包含表示层代码,处理用户界面和API接口。
  • src/shared: 包含共享模块,如常量、装饰器、异常处理等。
  • src/tests: 包含测试代码。
  • main.ts: 项目的入口文件。
  • test/initialization.ts: 测试初始化文件。
  • TRACING.md: 追踪文档。
  • tsconfig.build.json: TypeScript 构建配置文件。
  • tsconfig.json: TypeScript 配置文件。

2. 项目的启动文件介绍

main.ts

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  await app.listen(3000);
}
bootstrap();

启动文件介绍

  • NestFactory.create(AppModule): 创建 NestJS 应用实例。
  • app.listen(3000): 监听端口 3000。

3. 项目的配置文件介绍

tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "target": "es2017",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true,
    "skipLibCheck": true
  },
  "include": ["src/**/*"]
}

tsconfig.build.json

{
  "extends": "./tsconfig.json",
  "exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
}

配置文件介绍

  • tsconfig.json: TypeScript 编译选项,包括模块系统、目标版本、输出目录等。
  • tsconfig.build.json: 继承 tsconfig.json,排除 node_modulestestdist 和测试文件。

nestjs-boilerplate-microserviceNestjs Microservice boilerplate: apply DDD, CQRS, and Event Sourcing within an event driven architecture项目地址:https://gitcode.com/gh_mirrors/ne/nestjs-boilerplate-microservice

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

邬情然Harley

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值