Search code examples
nestjs

How to use config module on main.ts file


I have set a config module, according to https://docs.nestjs.com/techniques/configuration then how can I use it on main.ts??

nestjs version: 6.1.1


Solution

  • 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: configService.get('key');