I'm using node-config for configs in my Node app. One of the configurations I'm managing is a super-secret password that even I am not allowed to know. To handle this I've implemented a web app that a user can use to update the password in production without me being in the loop.
What I want to do is have the Node application modify the local.json config file and then tell config to reload configurations so that this configuration takes place without having to close and relaunch the Node application.
Is there a way to do that, or is restarting Node the only option for this?
Node-config allows you to create configuration files in your Node application for different deployment environments. With it, you can define a default configuration file that you intend to repeat across environments, then extend the default config to other environments, such as development, staging, etc.
The configuration files are located in the default config directory. The location can be overriden with the NODE_CONFIG_DIR environment variable. The NODE_ENV environment variable contains the name of our application's deployment environment; it is development by default.
json. nconf wrapper that simplifies work with environment specific configuration files.
Found the answer in this thread:
https://github.com/lorenwest/node-config/issues/34
After updating the config file you can force config to reload with this line:
delete require.cache[require.resolve('config')];
Worked like a charm!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With