Basically the JS file is a config file, where if an update is done to the file, changes will reflect real time in the NodeJS Server without restarting.
I've tried using fs.watch()
then reading the file via fs.createReadStream()
whenever a change event has occurred in the file. The file is read successfully but to my understanding, the read content is interpreted as a plain text.
Is there any way to read the file as JS instead so that I can easily integrate the changes in the file to the server?
Here's what the config file looks like
config.js
var SERVER_CONFIG = {
SSL_PATH: '/etc/letsencrypt/live/certificates/',
PORT: {
HTTP: 5555,
HTTPS: 5556
}
}
if (typeof module !== "undefined") {
module.exports.SERVER_CONFIG = SERVER_CONFIG;
}
Currently, how I use the config.js is as a module that is imported when the server starts.
eg
var SERVER_CONFIG = require('./config.js').SERVER_CONFIG;
var sslPath = SERVER_CONFIG.SSL_PATH;
http.listen(SERVER_CONFIG.PORT.HTTPS, function () {
console.log('http listening on *:' + SERVER_CONFIG.PORT.HTTPS);
});