https://github.com/sjinks/node-config-reloadable
Reloadable version of lorenwest/node-config
https://github.com/sjinks/node-config-reloadable
config configuration node-config reload-config
Last synced: 3 months ago
JSON representation
Reloadable version of lorenwest/node-config
- Host: GitHub
- URL: https://github.com/sjinks/node-config-reloadable
- Owner: sjinks
- License: mit
- Created: 2019-07-02T03:19:29.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2025-03-03T03:02:59.000Z (4 months ago)
- Last Synced: 2025-03-05T05:02:22.332Z (4 months ago)
- Topics: config, configuration, node-config, reload-config
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/config-reloadable
- Size: 969 KB
- Stars: 8
- Watchers: 4
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# node-config-reloadable
[](https://github.com/sjinks/node-config-reloadable/actions/workflows/build.yml)
[](https://www.npmjs.com/package/config-reloadable)Reloadable version of [lorenwest/node-config](https://github.com/lorenwest/node-config)
# Install
```sh
npm install --save config-reloadable
```# Why?
It looks like there is no [official support](https://github.com/lorenwest/node-config/issues/34) for reloading configuration files;
instead, the author suggest a [workaround](https://github.com/lorenwest/node-config/issues/34#issuecomment-9039129), 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](https://nodejs.org/api/modules.html#modules_require_cache)
for both `node-config` itself and all configuration files that have been loaded.# Example
```js
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`:
```js
const config = require('config-reloadable');let conf = config();
process.on('SIGHUP', function () {
conf = config.reloadConfigs();
});
```