How to catch an ENOENT with nodejs child_process.spawn?

As with many things in node, child processes can emit an error event. Add a listener for that and you will be able to catch it (no try-catch needed):

var spawn = require('child_process').spawn;
var child = spawn('foo');
child.on('error', function(err) {
  console.log('Oh noez, teh errurz: ' + err);
});

Leave a Comment

tech