Relevant source files
- index.js
- test-d/arguments/env.test-d.ts
- test-d/methods/list.test-d.ts
- readme.md
- docs/small.md
- docs/bash.md
- docs/windows.md
Getting Started
Purpose
This page explains how to install and use Execa in your projects.
How it Works
Execa is a thin wrapper around the core Node.js child_process module. It provides a simple and cross-platform way to run commands in your script, application or library.
Key Flows
- Execution: Run commands using the
$function, which takes a template string or a string with arguments. - Script: Use the script interface to run commands with a more traditional shell-like syntax.
- Input/Output: Pass any input type to the subprocess and return any output type.
- Piping: Pipe multiple subprocesses together to process output in a more complex way.
- Debugging: Use verbose mode, detailed errors, and custom logging to debug subprocesses.
Installation
To install Execa, run the following command:
npm install execa
Documentation
For more information on how to use Execa, refer to the Execa documentation.
Examples
Execution
import {execa} from 'execa';
const {stdout} = await execa`npm run build`;
console.log(stdout);
Script
import {$} from 'execa';
const {stdout: name} = await $`cat package.json`.pipe`grep name`;
console.log(name);
const branch = await $`git branch --show-current`;
await $`dep deploy --branch=${branch}`;
Input/Output
import {execa} from 'execa';
const {stdout} = await execa({input: 'Hello World!'});
console.log(stdout);
Piping
import {execa} from 'execa';
const {stdout, pipedFrom} = await execa`npm run build`
.pipe`sort`
.pipe`head -n 2`;
console.log(stdout);
console.log(pipedFrom[0].stdout);
console.log(pipedFrom[0].pipedFrom[0].stdout);
Debugging
import {execa} from 'execa';
await execa({verbose: true})`npm run build`;
Mermaid Diagram
graph TD
A[Install Execa] --> B[Import Execa]
B --> C[Run Command]
C --> D[Get Output]
D --> E[Log Output]
E --> F[Debug Subprocess]Sources: index.js