Recall & Review
beginner
What is a child process in Node.js?
A child process is a separate process created by a Node.js program to run tasks independently, allowing the main program to continue running without waiting.
Click to reveal answer
beginner
How do you listen for errors from a child process in Node.js?
You listen for the 'error' event on the child process object to catch errors like failure to start the process.
Click to reveal answer
intermediate
What does the 'exit' event on a child process indicate?
The 'exit' event fires when the child process ends. It provides the exit code and signal, which help determine if the process ended successfully or with an error.
Click to reveal answer
intermediate
Why should you handle both 'error' and 'exit' events when working with child processes?
Because 'error' catches startup failures, while 'exit' tells you if the process ended with an error code. Handling both ensures you catch all problems.
Click to reveal answer
intermediate
What is a common way to handle errors from a child process spawned with spawn()?
Attach listeners to 'error' and 'exit' events, check the exit code, and handle any error messages from stderr to respond properly.
Click to reveal answer
Which event should you listen to catch if a child process fails to start?
✗ Incorrect
The 'error' event is emitted if the child process fails to start or there is a problem spawning it.
What does an exit code of 0 usually mean for a child process?
✗ Incorrect
An exit code of 0 means the process finished without errors.
Which Node.js method creates a child process that allows streaming input/output?
✗ Incorrect
spawn() creates a child process with streams for stdin, stdout, and stderr.
If a child process emits an 'exit' event with a non-zero code, what does it mean?
✗ Incorrect
A non-zero exit code usually indicates the process ended due to an error.
Which event can you use to detect when a child process has fully closed all stdio streams?
✗ Incorrect
The 'close' event fires after the process ends and all stdio streams are closed.
Explain how to properly handle errors when spawning a child process in Node.js.
Think about events and exit codes.
You got /4 concepts.
Describe the difference between the 'error' and 'exit' events on a child process.
One is about starting, the other about ending.
You got /4 concepts.