LinuxCommandLibrary

bunx

Execute JavaScript package binaries

TLDR

Download and execute a package from the registry

$ bunx [package_name] "[command_argument]"
copy

Check the version of a locally installed package (if found)
$ bunx [package_name] --version
copy

Force an executable to run with the Bun runtime (instead of Node)
$ bunx --bun [package_name]
copy

Execute a binary that has a different name than its package
$ bunx [[-p|--package]] [package_name] [command]
copy

Download and execute a specific version of a package
$ bunx [package_name@version] "[command_argument]"
copy

SYNOPSIS

bunx [options] <command> [args...]
bunx [options] <package>@<version> [args...]

PARAMETERS

<command>
    The name of the executable from an npm package to run. bunx will locate it in node_modules or fetch it.

<package>@<version>
    Specifies a package name and an optional version (e.g., cowsay@1.5.0) to fetch and execute. If no version is specified, the latest stable version is used.

[args...]
    Any additional arguments to be passed directly to the invoked executable.

-h, --help
    Displays the help message for the bunx command itself.

--cwd <dir>
    Specifies the current working directory for the command execution.

DESCRIPTION

bunx is the Bun runtime's equivalent of npx in Node.js. It allows developers to execute binaries from npm packages without requiring them to be globally installed. When invoked, bunx first checks if the specified executable is available in the local node_modules directory. If not found, it efficiently downloads the necessary package to a temporary directory, executes the command, and then cleans up. This functionality is invaluable for one-off commands, scaffolding tools (like create-react-app), or running development utilities without cluttering global package installations. It leverages Bun's performance advantages, offering significantly faster execution compared to traditional methods. bunx streamlines development workflows by making it easy to access and run package-specific commands on demand.

CAVEATS

bunx requires the Bun runtime to be installed on your system. While it aims for npm compatibility, there might be edge cases or specific package features that behave differently compared to npx or npm due to Bun's distinct implementation. Always exercise caution when executing commands from untrusted packages, as bunx will download and run code from the internet.

USAGE EXAMPLES

Execute a package command:
bunx cowsay "Hello Bun!"

Scaffold a new project:
bunx create-react-app my-app

Run a specific version of a package:
bunx eslint@8.0.0 --init

COMPARISON WITH NPX

Both bunx and npx serve the same purpose: running npm package executables without global installation. The primary difference lies in their underlying runtime: bunx uses the Bun runtime (written in Zig), while npx uses Node.js. This often gives bunx a notable performance advantage in terms of execution speed and startup time.

COMPARISON WITH BUN RUN

While related, bunx and bun run have distinct uses.

bunx: Executes package binaries (e.g., cowsay, create-react-app) either locally or by fetching them.

bun run: Executes scripts defined in the "scripts" section of your project's package.json file (e.g., bun run start, bun run test).

HISTORY

bunx was introduced as an integral part of the Bun JavaScript runtime, which was created by Jarred Sumner and publicly launched in 2022. Bun's ambitious goal is to be an all-in-one toolkit for JavaScript and TypeScript development, encompassing a runtime, package manager, and bundler. bunx specifically emerged as Bun's answer to Node.js's npx, aiming to provide a significantly faster and more efficient way to execute package binaries. Its development reflects Bun's core philosophy of speed and consolidation within the JavaScript ecosystem.

SEE ALSO

bun(1), npx(1), npm(1), yarn(1)

Copied to clipboard