I have this example script from node describing how to send messages from either a Master or worker process using cluster. When I run this script, I am unable to verify the message from either the Master or worker. It appears the worker.on statement is not executing.
Can anyone explain how I can verify these messages from either process on the console during runtime and why the worker.on statement is not working? I would like to create a two-way communication handshake.
if (cluster.isMaster) {
var worker = cluster.fork();
worker.on("message", function(code) {
console.log("Parent received: " + code);
worker.send("this is from the test.js parent");
});
} else if (cluster.isWorker) {
process.on('message', function(msg) {
process.send(msg);
});
}