Created
October 10, 2016 22:06
-
-
Save kendru/2ad2b585d6bf963da424ea6b34f3732a to your computer and use it in GitHub Desktop.
Example of using SUGHUP with Node to reload config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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