execa
A better child_process
Why
Install
$ npm install --save execa
Usage
const execa = require('execa');
execa('echo', ['unicorns']).then(result => {
console.log(result.stdout);
});
execa.shell('echo unicorns').then(result => {
console.log(result.stdout);
});
execa.shell('exit 3').catch(error => {
console.log(error);
});
API
execa(file, [arguments], [options])
Execute a file directly.
Same options as child_process.execFile
.
Returns a promise for a result object with stdout
and stderr
properties.
execa.shell(command, [options])
Execute a command through the system shell. Prefer execa()
whenever possible, as it's both faster and safer.
Same options as child_process.exec
.
Returns a promise for a result object with stdout
and stderr
properties.
execa.spawn(file, [arguments], [options])
Spawn a file.
Same API as child_process.spawn
.
options
Additional exposed options:
stripEof
Type: boolean
Default: true
Strip EOF (last newline) from the output.
preferLocal
Type: boolean
Default: true
Prefer locally installed binaries when looking for a binary to execute.
If you $ npm install foo
, you can then execa('foo')
.
License
MIT © Sindre Sorhus