Bird
0
0

What is the main advantage of using spawn in Node.js for running commands compared to exec?

easy📝 Conceptual Q11 of 15
Node.js - Child Processes
What is the main advantage of using spawn in Node.js for running commands compared to exec?
AIt automatically retries failed commands.
BIt runs commands only in the background without output.
CIt streams output live without buffering all data first.
DIt converts output to JSON format automatically.
Step-by-Step Solution
Solution:
  1. Step 1: Understand spawn behavior

    spawn runs commands and streams their output as it happens, without waiting for the whole output to finish.
  2. Step 2: Compare with exec

    exec buffers the entire output before returning it, which can cause delays or memory issues with large outputs.
  3. Final Answer:

    It streams output live without buffering all data first. -> Option C
  4. Quick Check:

    spawn streams output live = B [OK]
Quick Trick: spawn streams output live, exec buffers all output [OK]
Common Mistakes:
  • Thinking spawn retries commands automatically
  • Assuming spawn hides output
  • Believing spawn formats output as JSON

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes