Unhandled errors in the child process will cause it to exit, which will emit the 'exit'
event on the child
object.
child.on('exit', function (code, signal) {
console.log('Child exited:', code, signal);
});
If the error is handled within the child, it can be sent as another message:
// in pChild.js
/* ... */.on('error', function (error) {
process.send({ error: error.message || error });
});
Updated answer
On child
process.on('uncaughtException', (err) => {
process.send({isError: true});
});
On master
master.on('message',({isError, data})=>{
if(isError) {
master.kill('SIGINT');
return;
}
console.log('message from child', data);
master.kill('SIGINT');
});