github.com/sindresorhus/execa
- Folder:fixtures
- File:.editorconfig
- File:.gitattributes
- File:.gitignore
- File:.travis.yml
- File:appveyor.yml
- File:index.js
- File:license
- File:package.json
- File:readme.md
- File:test.js
readme.md
execa

A better
child_process
Why
- Promise interface.
- Strips EOF from the output so you don't have to
stdout.trim(). - Supports shebang binaries cross-platform.
- Improved Windows support.
- Higher max buffer. 10 MB instead of 200 KB.
- Executes locally installed binaries by name.
Install
$ npm install --save execa
Usage
const execa = require('execa');
execa('echo', ['unicorns']).then(result => {
console.log(result.stdout);
//=> 'unicorns'
});
execa.shell('echo unicorns').then(result => {
console.log(result.stdout);
//=> 'unicorns'
});
// example of catching an error
execa.shell('exit 3').catch(error => {
console.log(error);
/*
{
message: 'Command failed: /bin/sh -c exit 3'
killed: false,
code: 3,
signal: null,
cmd: '/bin/sh -c exit 3',
stdout: '',
stderr: ''
}
*/
});
API
execa(file, [arguments], [options])
Execute a file.
Same options as child_process.execFile.
Returns a promise for a result object with stdout and stderr properties.
The promise instance has a pid property (ID of the child process) and a kill method (for sending signals to the child process).
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.
The promise instance has a pid property (ID of the child process) and a kill method (for sending signals to the child process).
execa.spawn(file, [arguments], [options])
Spawn a file.
Same API as child_process.spawn.
execa.sync(file, [arguments], [options])
Execute a file synchronously.
Same options as child_process.execFileSync, except that the default encoding is utf8 instead of buffer.
Returns stdout.
options
Additional 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