Performance: spawn for streaming processes
MEDIUM IMPACT
This affects how quickly data from child processes is handled and streamed without blocking the main event loop.
const { spawn } = require('child_process');
const child = spawn('some-long-running-command');
child.stdout.on('data', (chunk) => {
process.stdout.write(chunk);
});
child.stderr.on('data', (chunk) => {
process.stderr.write(chunk);
});const { exec } = require('child_process');
exec('some-long-running-command', (error, stdout, stderr) => {
if (error) {
console.error(`Error: ${error.message}`);
return;
}
console.log(stdout);
});| Pattern | Memory Usage | Event Loop Blocking | Responsiveness | Verdict |
|---|---|---|---|---|
| exec with callback | High (buffers full output) | Blocks until process ends | Low (waits for full output) | [X] Bad |
| spawn with streaming | Low (streams chunks) | Non-blocking | High (processes data as it arrives) | [OK] Good |