Node.js · Middle · Question 52 of 75
What is the difference between child_process.exec and child_process.spawn?
- 1
execruns JavaScript files,spawnruns binaries - 2
spawnworks only on Linux - ✓Correct answer:
execruns a command in a shell and buffers all output;spawnstreams output and runs without a shell by default
Explanation
Use spawn or execFile for large output or untrusted arguments. Passing user input to exec risks command injection.