Bird
0
0

How can you modify this code to handle large output without buffering issues?

hard📝 Application Q9 of 15
Node.js - Child Processes
How can you modify this code to handle large output without buffering issues?
const { execFile } = require('child_process');
execFile('someLargeOutputScript.sh', (error, stdout, stderr) => {
  if (error) throw error;
  console.log(stdout);
});
AIncrease buffer size option in execFile call
BUse <code>spawn</code> instead of <code>execFile</code> for streaming output
CSplit output manually after execFile finishes
DNo change needed, execFile handles large output automatically
Step-by-Step Solution
Solution:
  1. Step 1: Understand execFile buffering limits

    execFile buffers all output in memory, which can cause issues with large output.
  2. Step 2: Use spawn for streaming output

    spawn returns streams for stdout and stderr, allowing processing output as it arrives without buffering limits.
  3. Final Answer:

    Use spawn instead of execFile for streaming output -> Option B
  4. Quick Check:

    Large output needs spawn streaming [OK]
Quick Trick: Use spawn for large output streaming [OK]
Common Mistakes:
  • Assuming execFile can handle unlimited output
  • Trying to split output after buffering
  • Ignoring buffer size limits

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes