Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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 (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-04-22T22:23:26.000Z (7 months ago)
- Last Synced: 2024-04-24T03:16:52.655Z (7 months ago)
- Topics: config, configuration, node-config, reload-config
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/config-reloadable
- Size: 832 KB
- Stars: 7
- Watchers: 3
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# node-config-reloadable
[![Build and Test](https://github.com/sjinks/node-config-reloadable/actions/workflows/build.yml/badge.svg)](https://github.com/sjinks/node-config-reloadable/actions/workflows/build.yml)
[![npm version](https://img.shields.io/npm/v/config-reloadable.svg)](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();
});
```