How does Node.js handle child processes?
Instruction: Explain how Node.js can create and manage child processes, and why this capability is useful.
Context: This question assesses the candidate's understanding of the child_process module in Node.js and its applications in executing external processes or scripts from a Node.js application.
Updated
Official answer available
Read the opening below, then unlock the full answer and practical guidance.
The node:child_process module starts and manages separate operating-system processes. This is useful for external tools, process isolation and work that should not run on the main JavaScript thread.
spawn is asynchronous and exposes streams for standard input/output/error. exec is also asynchronous, but launches a shell and buffers output for its callback. execFile normally invokes the executable directly without a shell...