Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change configuration in runtime by changing environment variables using the module node-config

I'm trying to use the node-config module to change some parameters of my configuration (basically logging level) during runtime. In the official documentation says:

Environment variables can be used to override file configurations. Any environment variable that starts with $CONFIG_ is set into the CONFIG object.

I've checked that this is true when the server starts but it does not seem to work once it's up. (The handler of the watch function is never called when an environment variable is changed unlike a change in the runtime.json file or directly changing a config variable).

I'm currently watching the whole CONFIG object like this:

var CONFIG = require('config');
CONFIG.watch( CONFIG , null , function(object, propertyName, priorValue, newValue){
    console.log("Configuration change detected");
});

Does anyone know if this is possible?

like image 342
Miki de Arcayne Avatar asked Feb 16 '23 11:02

Miki de Arcayne


1 Answers

The environment is available during startup of a process. If the process is running, you won't be able to change the environment anymore, the process is in.

The only option is to restart the process or use other mechanisms to communicate with it. Say for example having a rest or tcp listener inside, where you can transfer your variable inside.

Best regards Robert

like image 75
robsp Avatar answered Mar 05 '23 17:03

robsp