如何在 main.ts 文件中使用配置模块 [英] How to use config module on main.ts file
问题描述
我已经根据 https://docs.nestjs.com/techniques/设置了一个配置模块配置 那么我如何在 main.ts 上使用它??
I have set a config module, according to https://docs.nestjs.com/techniques/configuration then how can I use it on main.ts??
nestjs 版本:6.1.1
nestjs version: 6.1.1
推荐答案
在您的 main.ts
文件中使用 NestFactory
方法创建您可以使用的应用程序后const configService = app.get
从上下文中获取服务.如果您想省略也可以使用的泛型.之后,您就像在应用程序中的其他任何地方一样使用它:configSerivce.get('key');
In your main.ts
file after you use the NestFactory
method to create the application you can use const configService = app.get<ConfigService>(ConfigService);
to get the service from the context. If you want to leave out the generics that works too. After that you use it just like you would anywhere else in your app: configSerivce.get('key');
这篇关于如何在 main.ts 文件中使用配置模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!