Interface Options<EncodingType>

interface Options<EncodingType> {
    all?: boolean;
    argv0?: string;
    buffer?: boolean;
    cleanup?: boolean;
    cwd?: string;
    detached?: boolean;
    encoding?: EncodingType;
    env?: ProcessEnv;
    execPath?: string;
    extendEnv?: boolean;
    gid?: number;
    input?: string | Buffer | Readable;
    killSignal?: string | number;
    localDir?: string;
    maxBuffer?: number;
    preferLocal?: boolean;
    reject?: boolean;
    serialization?: "json" | "advanced";
    shell?: string | boolean;
    stderr?: StdioOption;
    stdin?: StdioOption;
    stdio?:
        | "pipe"
        | "ignore"
        | "inherit"
        | readonly StdioOption[];
    stdout?: StdioOption;
    stripFinalNewline?: boolean;
    timeout?: number;
    uid?: number;
    windowsHide?: boolean;
    windowsVerbatimArguments?: boolean;
}

Type Parameters

  • EncodingType = string

Hierarchy (view full)

Properties

all?: boolean

Add an .all property on the promise and the resolved value. The property contains the output of the process with stdout and stderr interleaved.

false
argv0?: string

Explicitly set the value of argv[0] sent to the child process. This will be set to command or file if not specified.

buffer?: boolean

Buffer the output from the spawned process. When set to false, you must read the output of stdout and stderr (or all if the all option is true). Otherwise the returned promise will not be resolved/rejected.

If the spawned process fails, error.stdout, error.stderr, and error.all will contain the buffered data.

true
cleanup?: boolean

Kill the spawned process when the parent process exits unless either: - the spawned process is detached - the parent process is terminated abruptly, for example, with SIGKILL as opposed to SIGTERM or a normal exit

true
cwd?: string

Current working directory of the child process.

process.cwd()
detached?: boolean

Prepare child to run independently of its parent process. Specific behavior depends on the platform.

false
encoding?: EncodingType

Specify the character encoding used to decode the stdout and stderr output. If set to null, then stdout and stderr will be a Buffer instead of a string.

'utf8'
env?: ProcessEnv

Environment key-value pairs. Extends automatically from process.env. Set extendEnv to false if you don't want this.

process.env
execPath?: string

Path to the Node.js executable to use in child processes.

This can be either an absolute path or a path relative to the cwd option.

Requires preferLocal to be true.

For example, this can be used together with get-node to run a specific Node.js version in a child process.

process.execPath
extendEnv?: boolean

Set to false if you don't want to extend the environment variables when providing the env property.

true
gid?: number

Sets the group identity of the process.

input?: string | Buffer | Readable

Write some input to the stdin of your binary.

killSignal?: string | number

Signal value to be used when the spawned process will be killed.

'SIGTERM'
localDir?: string

Preferred path to find locally installed binaries in (use with preferLocal).

process.cwd()
maxBuffer?: number

Largest amount of data in bytes allowed on stdout or stderr. Default: 100 MB.

100_000_000
preferLocal?: boolean

Prefer locally installed binaries when looking for a binary to execute.

If you $ npm install foo, you can then execa('foo').

false
reject?: boolean

Setting this to false resolves the promise with the error instead of rejecting it.

true
serialization?: "json" | "advanced"

Specify the kind of serialization used for sending messages between processes when using the stdio: 'ipc' option or execa.node(): - json: Uses JSON.stringify() and JSON.parse(). - advanced: Uses v8.serialize()

Requires Node.js 13.2.0 or later.

More info.

'json'
shell?: string | boolean

If true, runs command inside of a shell. Uses /bin/sh on UNIX and cmd.exe on Windows. A different shell can be specified as a string. The shell should understand the -c switch on UNIX or /d /s /c on Windows.

We recommend against using this option since it is:

  • not cross-platform, encouraging shell-specific syntax.
  • slower, because of the additional shell interpretation.
  • unsafe, potentially allowing command injection.
false
stderr?: StdioOption

Same options as stdio.

'pipe'
stdin?: StdioOption

Same options as stdio.

'pipe'
stdio?:
    | "pipe"
    | "ignore"
    | "inherit"
    | readonly StdioOption[]

Child's stdio configuration.

'pipe'
stdout?: StdioOption

Same options as stdio.

'pipe'
stripFinalNewline?: boolean

Strip the final newline character from the output.

true
timeout?: number

If timeout is greater than 0, the parent will send the signal identified by the killSignal property (the default is SIGTERM) if the child runs longer than timeout milliseconds.

0
uid?: number

Sets the user identity of the process.

windowsHide?: boolean

On Windows, do not create a new console window. Please note this also prevents CTRL-C from working on Windows.

true
windowsVerbatimArguments?: boolean

If true, no quoting or escaping of arguments is done on Windows. Ignored on other platforms. This is set to true automatically when the shell option is true.

false