Skip to content

Instantly share code, notes, and snippets.

@kendru
Created October 10, 2016 22:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kendru/2ad2b585d6bf963da424ea6b34f3732a to your computer and use it in GitHub Desktop.
Save kendru/2ad2b585d6bf963da424ea6b34f3732a to your computer and use it in GitHub Desktop.
Example of using SUGHUP with Node to reload config
// Example /tmp/srv.conf.json
// {"name":"bill"}
var fs = require('fs');
var config = {
name: ''
};
function loadConfig() {
fs.readFile('/tmp/srv.conf.json', 'utf8', function(err, data) {
if (err) throw err;
config = JSON.parse(data);
console.log('Loaded config');
});
}
loadConfig();
setInterval(function() {
console.log('Name:', config.name);
}, 1000);
process.stdin.resume();
process.on('SIGHUP', loadConfig);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment