小编Kev*_*lin的帖子

引导微服务时获取 ConfigService 的正确方法

我想知道在引导我的微服务期间是否以正确的方式获取 ConfigService。

有没有办法使用 NestFactory.createMicroservice() 来做到这一点?

async function bootstrap() {
  const app = await NestFactory.create(CoreModule, {
    logger: new MyLogger(),
  });
  const configService: ConfigService = app.get(ConfigService);
  app.connectMicroservice({
    transport: Transport.TCP,
    options: {
      port: configService.PORT,
    },
  });
  await app.startAllMicroservicesAsync();
}
Run Code Online (Sandbox Code Playgroud)

node.js microservices nestjs

4
推荐指数
1
解决办法
4102
查看次数

标签 统计

microservices ×1

nestjs ×1

node.js ×1