config-reloadable

Reloadable version of config

Usage no npm install needed!

<script type="module">
  import configReloadable from 'https://cdn.skypack.dev/config-reloadable';
</script>

README

node-config-reloadable

Build and Test CI npm version Scrutinizer Code Quality Code Coverage Build Status

Reloadable version of lorenwest/node-config

Install

npm install --save config-reloadable

Why?

It looks like there is no official support for reloading configuration files; instead, the author suggest a workaround, which, unfortunately, does not always work (for example, if your configuration files are *.js).

config-reloadable forces node-config to reload configuration files by clearing the require cache for both node-config itself and all configuration files that have been loaded.

Example

const config = require('config-reloadable');

console.log(config().something);

// Now change that `something`

config.reloadConfigs();

console.log(config().something);

// Displayed values should differ

Instead of config.reloadConfigs() it is possible to use config(true) (it is less intuitive but makes the code less verbose).

Reload configuration files on SIGHUP:

const config = require('config-reloadable');

let conf = config();

process.on('SIGHUP', function () {
  conf = config.reloadConfigs();
});