This is what I am doing:
var fork = require('child_process').fork;
var child = fork('some_script');
child.on('error', function(err) {
console.log(err);
});
I want to catch the error if the script is not valid. There is an answer posted here which works great for spawn but fails for fork. There is also this answer which helps to debug but does not serve my purpose. I want to log the error as the script is dynamically generated.
process.on('uncaughtException', function (exception) { ...}
is neither recommended nor will work, I think...
UPDATE: Yes, it is a duplicate. Sorry I missed it. However, I am repeating the comment of RobertKlep here. Now the code is 1 instead of 8 in the cited answer. Thats important to note.