You don't have to restart your Node.js app to apply new configuration. Simply update the configuration files. This repository is forked from lorenwest/node-config and more specifically this Pull Request.
Install in your app directory, and edit the default config file.
$ npm install config-dynamic
$ mkdir config
$ vi config/default.json
{
// Customer module configs
"foo": {
"bar": "fizz"
}
}
Example express server that returns the config value:
$ npm install express
$ touch index.js
const config = require('config')
const express = require('express')
const app = express()
const port = 3000
app.get('/', (req, res) => {
const dbConfig = config.get('foo.bar')
console.log(dbConfig) // Display the updated configuration
res.send(dbConfig)
})
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})
Start your app server:
$ node index.js
Example app listening at http://localhost:3000
Poll the server for the latest configuration:
$ curl localhost:3000
fizz
Update config/default.json.
{
// Customer module configs
"foo": {
"bar": "buzz"
}
}
Poll the server for the latest configuration:
$ curl localhost:3000
buzz
May be freely distributed under the MIT license.