What is the difference between spawn() and exec()?
Both create child processes, but:
- spawn() streams data (good for large outputs)
- exec() buffers data (good for small outputs)
const { spawn, exec } = require('child_process');
// spawn example
const ls = spawn('ls', ['-lh', '/usr']);
ls.stdout.on('data', (data) => console.log(`Output: ${data}`));
// exec example
exec('ls -lh /usr', (error, stdout) => console.log(stdout));