Execa runs commands in your script, application or library. Unlike shells, it is optimized for programmatic usage. Built on top of the child_process core module.
const {stdout, pipedFrom} = await execa`npm run build`
.pipe`sort`
.pipe`head -n 2`;
// Output of `npm run build | sort | head -n 2`console.log(stdout);
// Output of `npm run build | sort`console.log(pipedFrom[0].stdout);
// Output of `npm run build`console.log(pipedFrom[0].pipedFrom[0].stdout);
// Similar to: npm run build < input.txtawaitexeca({stdin: {file: 'input.txt'}})`npm run build`;
File output
// Similar to: npm run build > output.txtawaitexeca({stdout: {file: 'output.txt'}})`npm run build`;
Split into text lines
const {stdout} = awaitexeca({lines: true})`npm run build`;
// Print first 10 linesconsole.log(stdout.slice(0, 10).join('\n'));
Streaming
Iterate over text lines
forawait (const line of execa`npm run build`) {
if (line.includes('WARN')) {
console.warn(line);
}
}
Transform/filter output
let count = 0;
// Filter out secret lines, then prepend the line numberconst transform = function * (line) {
if (!line.includes('secret')) {
yield`[${count++}] ${line}`;
}
};
awaitexeca({stdout: transform})`npm run build`;
ShellJS is a portable Unix shell commands implementation for Node.js. It offers a higher-level API for executing commands but does not support returning promises natively.
Cross-spawn is a cross-platform solution for spawning child processes. It aims to solve compatibility issues on Windows but does not provide a promise-based API.
The npm package execa receives a total of 137,581,936 weekly downloads. As such, execa popularity was classified as popular.
We found that execa demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.It has 2 open source maintainers collaborating on the project.
On Front Lines’ Early Adopters: CISO podcast, Andrew Becherer shares lessons from Datadog, weighs the long-term costs of AI-built tools, and explains how founders can actually gain a CISO’s trust.
Socket for Origin scans dependency changes in pull requests and flags security risks based on your team’s policies. Now available in Cursor’s App Marketplace.