Recall & Review
beginner
What does the
spawn function in Node.js do?It starts a new process to run a command or script, allowing you to stream data to and from that process without waiting for it to finish.
Click to reveal answer
intermediate
How does
spawn differ from exec in Node.js?spawn streams data in chunks and is better for large outputs, while exec buffers all output and returns it at once, which can cause memory issues with big data.Click to reveal answer
beginner
What are the main streams available on a
spawn child process?The main streams are
stdout for standard output, stderr for error output, and stdin for input to the process.Click to reveal answer
beginner
Why is streaming output from
spawn useful in real-life applications?It lets you process data as it arrives, like showing progress or handling large files without waiting for the whole task to finish, making apps faster and more responsive.
Click to reveal answer
intermediate
How can you handle errors when using
spawn?Listen to the
error event on the spawned process and also check the stderr stream for error messages.Click to reveal answer
Which Node.js module provides the
spawn function?✗ Incorrect
The spawn function is part of the child_process module used to create new processes.
What type of data does
spawn return for output streams?✗ Incorrect
spawn streams output data in chunks, allowing real-time processing.
Which event should you listen to for errors when using
spawn?✗ Incorrect
The error event signals problems starting or running the child process.
Why might you choose
spawn over exec?✗ Incorrect
spawn streams output, making it better for large data than exec, which buffers all output.
Which stream do you write to if you want to send input to a spawned process?
✗ Incorrect
stdin is the writable stream to send input to the child process.
Explain how you would use
spawn to run a command and process its output as it streams.Think about how streams let you handle data bit by bit.
You got /4 concepts.
Describe the differences between
spawn and exec and when to use each.Consider memory use and output size.
You got /4 concepts.