I'm setting up error handling for a child process in my node application, and I'm wondering about these two options:
childProcess.on('error', err => {
// omitted
});
// do we need both this and the preceding handler?
childProcess.stderr.on('data', data => {
// omitted
});
What's the difference? Are both needed?
The child process error
event is fired when node has a problem starting, stopping or managing the child process.
stderr
is one of the output channels for the child process once it's running. The data
event can be fired many times in normal operation of a process and can often include important information about error conditions of the process. You would normally handle stdout
in a similar fashion to stderr
.
The exit
events code
value can also be important for a child process. Often processes will exit with a non 0
return code to signal an issue occurred.