根据此documentation,您将配置导入AppModule。
我正在尝试访问main.ts文件中引导程序级别的配置。
像这样:
const app = await NestFactory.create(AppModule);
if (config.get('swagger.enabled'))
{
initSwagger(app);
}
await app.listen(8080);
我现在无法访问配置的问题,只有其他模块才能访问配置,如下所示:
@Injectable()
export class SomeService {
constructor(private readonly httpService: HttpService,
private readonly config: ConfigService) {}
}
我的问题:如何在引导程序级别访问“ nestjs-config”
答案 0 :(得分:2)
在创建服务器之后,但在开始监听端口之前,您可以在main.ts
中进行const config = app.get(ConfigService)
并可以访问ConfigService
。