Best practice to use config service in NestJS Module

前端 未结 2 1156
旧时难觅i
旧时难觅i 2021-02-19 03:58

I want to use environment variables to configure the HttpModule per module, from the docs I can use the configuration like this:

@Module({
  imports:         


        
2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-19 04:42

    I also encountered several issues with implementing a ConfigService as described in the NestJS documentation (no type-safety, no modularity of configuration values, ...), I wrote down our company's final NestJS configuration management strategy in great detail here: NestJS Configuration Management

    The basic idea is to have a central config module that loads all configuration values from the processes' environment. However, instead of providing a single service to all modules, each module can inject a dedicated subset of the configuration values! So each module contains a class that specifies all configuration values that this module needs to be provided at runtime. This simultaneously gives the developer type-safe access to configuration values (instead of using string literals throughout the codebase)

    Hope this pattern also works for your use-case :)

提交回复
热议问题