zx

JavaScript/TypeScript library and runner that wraps child_process with a $`...` template tag for writing cross-platform shell scripts with escaped arguments.

install· npm

zx is a scripting tool that provides cross-platform wrappers around Node.js child_process. Scripts use the $ template tag to run commands, for example await $git branch --show-current. Interpolated values are escaped automatically, so a variable such as 'foo bar' can be passed into mkdir /tmp/${name} safely. The package also sets sensible defaults for process execution.

Scripts can start with a #!/usr/bin/env zx shebang and are written in JavaScript or TypeScript. Because commands return promises, standard JavaScript constructs work with them, such as await for sequencing and Promise.all for running several commands in parallel. Command output can be stored in variables and passed to later commands, as in the README's branch-name deploy example.

zx runs on Linux, macOS and Windows. It supports Node.js 12.17.0 or later, Bun 1.0.0 or later, Deno 1.x and 2.x, and GraalVM Node.js. It works with Bash or PowerShell as the underlying shell and supports both CJS and ESM modules. A reduced variant, zx@lite, is documented separately. It suits developers and DevOps engineers who want to replace complex Bash scripts with JavaScript or TypeScript.

Installation

# via npm
npm install zx

Alternatives & related tools

add a badge to your README

Maintain zx? Show that it's featured on trmn. The badge links back to this page.

Featured on trmn
Markdown
[![Featured on trmn](https://www.trmn.sh/badge/zx.svg)](https://www.trmn.sh/tools/zx?utm_source=badge)
HTML
<a href="https://www.trmn.sh/tools/zx?utm_source=badge"><img src="https://www.trmn.sh/badge/zx.svg" alt="Featured on trmn" height="20"></a>