I'm trying to send data from a my main app to a child process. I've tried a few different alternatives but I'm currently stuck. Advice or pointers is very much appreciated.
I'm following the documentation at http://pm2.keymetrics.io/docs/usage/pm2-api/
index.js:
var pm2 = require('pm2');
var processName = "pm2_app";
console.log("hello world!");
pm2.connect(function(err) {
if (err) {
console.error(err);
process.exit(2);
}
pm2.start({
script : "pm2_app.js" // Script to be run
}, function(err, apps) {
if(err) {
console.log(err);
}
console.log("app started!");
pm2.list(function(err, list) {
console.log("Child process started with pid: " + list[0].pid);
pm2.sendDataToProcessId({
type : 'process:msg',
data : {
some : 'data',
hello : true
},
id : list[0].pid
},
function(err, res) {
console.log(err);
console.log("message sent");
});
pm2.disconnect();
});
});
});
pm2_app.js:
var start = Date.now();
setInterval(function(){
console.log(Date.now() - start);
}, 1000);
process.on('message', function(packet) {
console.log("got message from mr. Rabbit");
console.log(packet);
});
process.on('process:msg', ....)
– Gerbil