Take care of your
spawn()
- Returns an
await
-able promise - Collects
stdout
andstderr
buffers - Emits events "stdout" and "stderr"
- Automatically kills all spawn processes when parent process dies
yarn add spawndamnit
Basic:
const spawn = require('spawndamnit');
async function main() {
let child = spawn('npm', ['star', 'spawndamnit']);
child.on('stdout', data => console.log(data.toString()));
child.on('stderr', data => console.error(data.toString()));
let { code, stdout, stderr } = await child;
console.log(code === 0 ? 'success' : 'error');
}