Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can node-config reload configurations without restarting Node?

Tags:

node.js

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?

like image 886
Jim Lowell Avatar asked Mar 10 '15 21:03

Jim Lowell


People also ask

How does node config work?

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.

Where is node js configuration file?

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.

What is config JSON in node JS?

json. nconf wrapper that simplifies work with environment specific configuration files.


1 Answers

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!

like image 196
Jim Lowell Avatar answered Nov 14 '22 23:11

Jim Lowell