Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use config module on main.ts file

Tags:

nestjs

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

like image 416
Tung Tse Avatar asked Nov 25 '25 16:11

Tung Tse


1 Answers

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');

like image 136
Jay McDoniel Avatar answered Nov 28 '25 13:11

Jay McDoniel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!