const {cwd} = await execa`npm run build`;
console.log(cwd); // Current directory when running the command
await execa({cwd: '/path/to/cwd'})`npm run build`;
await execa('./node_modules/bin/eslint');
The preferLocal
option can be used to automatically find binaries installed in local node_modules
.
await execa('eslint', {preferLocal: true});
Those are searched in the current or any parent directory. The localDir
option can select a different directory.
await execa('eslint', {preferLocal: true, localDir: '/path/to/dir'});
Execa can be combined with get-bin-path
to test the current package's binary. As opposed to hard-coding the path to the binary, this validates that the package.json
bin
field is correctly set up.
import {execa} from 'execa';
import {getBinPath} from 'get-bin-path';
const binPath = await getBinPath();
await execa(binPath);
When the detached
option is true
, the subprocess runs independently from the current process.
Specific behavior depends on the platform. More info..
await execa({detached: true})`npm run start`;