I ask about this since I don’t have the tool or time to test it right now, but the idea bothers me. I myself will answer this when I have time to play with him.
In node.js, how does require () work? Does it store the required function in memory? or make it read the file again?
Exemple:
launcher.js
var cluster = require('cluster');
if (cluster.isMaster) {
cluster.fork();
cluster.on('exit', function () {
cluster.fork();
}
}
if (cluster.isWorker) {
var self = require('self_modifying.js');
self.start()
}
As long as the self_modification.js function has a start () function, which is the "main" one, it can self-update by simply modifying its own source file and process.exit (0), and so reloading with this new code?
source
share