Gathering detailed insights and metrics for execa
Gathering detailed insights and metrics for execa
Gathering detailed insights and metrics for execa
Gathering detailed insights and metrics for execa
npm install execa
Typescript
Module System
Min. Node Version
Node Version
NPM Version
97.5
Supply Chain
98.8
Quality
83.1
Maintenance
100
Vulnerability
100
License
JavaScript (79.25%)
TypeScript (20.75%)
Total Downloads
18,480,527,736
Last Day
20,416,709
Last Week
98,992,676
Last Month
446,068,929
Last Year
4,592,637,482
MIT License
7,216 Stars
811 Commits
239 Forks
41 Watchers
1 Branches
62 Contributors
Updated on Jul 29, 2025
Latest Version
9.6.0
Package Id
execa@9.6.0
Unpacked Size
316.71 kB
Size
84.24 kB
File Count
142
NPM Version
10.9.2
Node Version
20.19.1
Published on
May 26, 2025
Cumulative downloads
Total Downloads
Last Day
16.2%
20,416,709
Compared to previous day
Last Week
-1.7%
98,992,676
Compared to previous week
Last Month
-5.3%
446,068,929
Compared to previous month
Last Year
18%
4,592,637,482
Compared to previous year
Process execution for humans
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.
zx
.npx
.PATHEXT
, graceful termination, and more.Uint8Array
s, iterables, objects and almost any other type.stdout
and stderr
similar to what is printed on the terminal.1npm install execa
Execution:
Input/output:
Advanced usage:
1import {execa} from 'execa'; 2 3const {stdout} = await execa`npm run build`; 4// Print command's output 5console.log(stdout);
1import {$} from 'execa'; 2 3const {stdout: name} = await $`cat package.json`.pipe`grep name`; 4console.log(name); 5 6const branch = await $`git branch --show-current`; 7await $`dep deploy --branch=${branch}`; 8 9await Promise.all([ 10 $`sleep 1`, 11 $`sleep 2`, 12 $`sleep 3`, 13]); 14 15const directoryName = 'foo bar'; 16await $`mkdir /tmp/${directoryName}`;
1$ npm install -D eslint
1await execa({preferLocal: true})`eslint`;
1const {stdout, pipedFrom} = await execa`npm run build` 2 .pipe`sort` 3 .pipe`head -n 2`; 4 5// Output of `npm run build | sort | head -n 2` 6console.log(stdout); 7// Output of `npm run build | sort` 8console.log(pipedFrom[0].stdout); 9// Output of `npm run build` 10console.log(pipedFrom[0].pipedFrom[0].stdout);
1const {all} = await execa({all: true})`npm run build`; 2// stdout + stderr, interleaved 3console.log(all);
1const {stdout} = await execa({stdout: ['pipe', 'inherit']})`npm run build`; 2// stdout is also printed to the terminal 3console.log(stdout);
1const getInputString = () => { /* ... */ }; 2const {stdout} = await execa({input: getInputString()})`sort`; 3console.log(stdout);
1// Similar to: npm run build < input.txt 2await execa({stdin: {file: 'input.txt'}})`npm run build`;
1// Similar to: npm run build > output.txt 2await execa({stdout: {file: 'output.txt'}})`npm run build`;
1const {stdout} = await execa({lines: true})`npm run build`; 2// Print first 10 lines 3console.log(stdout.slice(0, 10).join('\n'));
1for await (const line of execa`npm run build`) { 2 if (line.includes('WARN')) { 3 console.warn(line); 4 } 5}
1let count = 0; 2 3// Filter out secret lines, then prepend the line number 4const transform = function * (line) { 5 if (!line.includes('secret')) { 6 yield `[${count++}] ${line}`; 7 } 8}; 9 10await execa({stdout: transform})`npm run build`;
1const response = await fetch('https://example.com'); 2await execa({stdin: response.body})`sort`;
1import {execa} from 'execa'; 2import {pipeline} from 'node:stream/promises'; 3import {createReadStream, createWriteStream} from 'node:fs'; 4 5await pipeline( 6 createReadStream('./input.txt'), 7 execa`node ./transform.js`.duplex(), 8 createWriteStream('./output.txt'), 9);
1// parent.js 2import {execaNode} from 'execa'; 3 4const subprocess = execaNode`child.js`; 5await subprocess.sendMessage('Hello from parent'); 6const message = await subprocess.getOneMessage(); 7console.log(message); // 'Hello from child'
1// child.js 2import {getOneMessage, sendMessage} from 'execa'; 3 4const message = await getOneMessage(); // 'Hello from parent' 5const newMessage = message.replace('parent', 'child'); // 'Hello from child' 6await sendMessage(newMessage);
1// main.js 2import {execaNode} from 'execa'; 3 4const ipcInput = [ 5 {task: 'lint', ignore: /test\.js/}, 6 {task: 'copy', files: new Set(['main.js', 'index.js']), 7}]; 8await execaNode({ipcInput})`build.js`;
1// build.js 2import {getOneMessage} from 'execa'; 3 4const ipcInput = await getOneMessage();
1// main.js
2import {execaNode} from 'execa';
3
4const {ipcOutput} = await execaNode`build.js`;
5console.log(ipcOutput[0]); // {kind: 'start', timestamp: date}
6console.log(ipcOutput[1]); // {kind: 'stop', timestamp: date}
1// build.js 2import {sendMessage} from 'execa'; 3 4const runBuild = () => { /* ... */ }; 5 6await sendMessage({kind: 'start', timestamp: new Date()}); 7await runBuild(); 8await sendMessage({kind: 'stop', timestamp: new Date()});
1// main.js 2import {execaNode} from 'execa'; 3 4const controller = new AbortController(); 5setTimeout(() => { 6 controller.abort(); 7}, 5000); 8 9await execaNode({ 10 cancelSignal: controller.signal, 11 gracefulCancel: true, 12})`build.js`;
1// build.js 2import {getCancelSignal} from 'execa'; 3 4const cancelSignal = await getCancelSignal(); 5const url = 'https://example.com/build/info'; 6const response = await fetch(url, {signal: cancelSignal});
1import {execa, ExecaError} from 'execa'; 2 3try { 4 await execa`unknown command`; 5} catch (error) { 6 if (error instanceof ExecaError) { 7 console.log(error); 8 } 9 /* 10 ExecaError: Command failed with ENOENT: unknown command 11 spawn unknown ENOENT 12 at ... 13 at ... { 14 shortMessage: 'Command failed with ENOENT: unknown command\nspawn unknown ENOENT', 15 originalMessage: 'spawn unknown ENOENT', 16 command: 'unknown command', 17 escapedCommand: 'unknown command', 18 cwd: '/path/to/cwd', 19 durationMs: 28.217566, 20 failed: true, 21 timedOut: false, 22 isCanceled: false, 23 isTerminated: false, 24 isMaxBuffer: false, 25 code: 'ENOENT', 26 stdout: '', 27 stderr: '', 28 stdio: [undefined, '', ''], 29 pipedFrom: [] 30 [cause]: Error: spawn unknown ENOENT 31 at ... 32 at ... { 33 errno: -2, 34 code: 'ENOENT', 35 syscall: 'spawn unknown', 36 path: 'unknown', 37 spawnargs: [ 'command' ] 38 } 39 } 40 */ 41}
1await execa`npm run build`; 2await execa`npm run test`;
1import {execa as execa_} from 'execa'; 2import {createLogger, transports} from 'winston'; 3 4// Log to a file using Winston 5const transport = new transports.File({filename: 'logs.txt'}); 6const logger = createLogger({transports: [transport]}); 7const LOG_LEVELS = { 8 command: 'info', 9 output: 'verbose', 10 ipc: 'verbose', 11 error: 'error', 12 duration: 'info', 13}; 14 15const execa = execa_({ 16 verbose(verboseLine, {message, ...verboseObject}) { 17 const level = LOG_LEVELS[verboseObject.type]; 18 logger[level](message, verboseObject); 19 }, 20}); 21 22await execa`npm run build`; 23await execa`npm run test`;
No vulnerabilities found.