aboutsummaryrefslogtreecommitdiff
path: root/docs/cli/bunx.md
blob: 5a70c1e706b4abfe20102f7816db004495fec47e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
{% callout %}
**Note** — `bunx` is an alias for `bun x`. The `bunx` CLI will be auto-installed when you install `bun`.
{% /callout %}

Use `bunx` to auto-install and run packages from `npm`. It's Bun's equivalent of `npx` or `yarn dlx`.

```bash
$ bunx cowsay "Hello world!"
```

{% callout %}
⚡️ **Speed** — With Bun's fast startup times, `bunx` is [roughly 100x faster](https://twitter.com/jarredsumner/status/1606163655527059458) than `npx` for locally installed packages.
{% /callout %}

Packages can declare executables in the `"bin"` field of their `package.json`. These are known as _package executables_ or _package binaries_.

```jsonc#package.json
{
  // ... other fields
  "name": "my-cli",
  "bin": {
    "my-cli": "dist/index.js"
  }
}
```

These executables are commonly plain JavaScript files marked with a [shebang line](<https://en.wikipedia.org/wiki/Shebang_(Unix)>) to indicate which program should be used to execute them. The following file indicates that it should be executed with `node`.

```js#dist/index.js
#!/usr/bin/env node

console.log("Hello world!");
```

These executables can be run with `bunx`,

```bash
$ bunx my-cli
```

As with `npx`, `bunx` will check for a locally installed package first, then fall back to auto-installing the package from `npm`. Installed packages will be stored in Bun's global cache for future use.

## Arguments and flags

To pass additional command-line flags and arguments through to the executable, place them after the executable name.

```bash
$ bunx my-cli --foo bar
```

## Shebangs

By default, Bun respects shebangs. If an executable is marked with `#!/usr/bin/env node`, Bun will spin up a `node` process to execute the file. However, in some cases it may be desirable to run executables using Bun's runtime, even if the executable indicates otherwise. To do so, include the `--bun` flag.

```bash
$ bunx --bun my-cli
```

The `--bun` flag must occur _before_ the executable name. Flags that appear _after_ the name are passed through to the executable.

```bash
$ bunx --bun my-cli # good
$ bunx my-cli --bun # bad
```

<!-- ## Environment variables

Bun automatically loads environment variables from `.env` files before running a file, script, or executable. The following files are checked, in order:

1. `.env.local` (first)
2. `NODE_ENV` === `"production"` ? `.env.production` : `.env.development`
3. `.env`

To debug environment variables, run `bun run env` to view a list of resolved environment variables. -->
>-2/+5 2023-09-01Add configuration options to extensionGravatar Ashcon Partovi 5-5/+137 2023-09-01Fix run button starting cwd at /Gravatar Ashcon Partovi 1-0/+2 2023-09-01fix(runtime): fix dns_resolver crash (#4435)Gravatar dave caruso 3-17/+19 2023-09-01Fix background colorGravatar Ashcon Partovi 1-2/+3 2023-09-01Allow older versions of VSCodeGravatar Ashcon Partovi 2-6/+5 2023-09-01Fix README for extensionGravatar Ashcon Partovi 2-7/+12 2023-09-01Update VSCode extensionGravatar Ashcon Partovi 1-3/+4 2023-09-01Fix breakpoint on entry for extensionGravatar Ashcon Partovi 5-18/+15 2023-09-01Add Bun.canReload event to inspectorGravatar Ashcon Partovi 2-0/+17 2023-08-31JavaScript Debug Terminal == Bun TerminalGravatar Ashcon Partovi 1-0/+32 2023-08-31fix(runtime): `fs.cp` edge cases (#4439)Gravatar dave caruso 2-8/+44 2023-08-31only set initial debugger breakpoint once (#4441)Gravatar Dylan Conway 1-2/+11 2023-08-31Make breakpoints faster in VSCode extensionGravatar Ashcon Partovi 1-241/+327 2023-08-31`bun install` correctly join dependency URLs (#4421)Gravatar Julian 6-64/+243 2023-08-31get name if not provided in `FormData.append` (#4434)Gravatar Dylan Conway 4-5/+45 2023-08-31Fix vscode debug terminalGravatar Ashcon Partovi 1-21/+0 Phillips 1-5/+5 2024-02-26Prevent errors in rendering from crashing server (#10221)Gravatar Matthew Phillips 7-14/+78 2024-02-26fix: svelte 5 mount/hydrate api change. (#10224)Gravatar 前端子鱼 3-5/+12 2024-02-24[ci] formatGravatar Arsh 1-9/+30 2024-02-24prevent warning: `Astro.request.headers` is not available in "static" output ...Gravatar Arsh 2-27/+30 2024-02-23Improved error logging from config (#10207)Gravatar Ben Holmes 4-36/+67 2024-02-23[ci] formatGravatar Arsh 3-3/+3 2024-02-23fix(dev): remove params for prerendered pages (#10199)Gravatar Arsh 9-13/+78 2024-02-23[ci] release (#10213)astro@4.4.4@astrojs/vercel@7.3.3@astrojs/node@8.2.1@astrojs/db@0.4.0Gravatar Houston (Bot) 41-177/+95 2024-02-23Fixes edge middleware calling nested routes (#10215)Gravatar Matthew Phillips 2-1/+6 2024-02-23Adds an error message for non-string transition:name values (#10205)Gravatar Martin Trapp 2-0/+8 2024-02-23[ci] formatGravatar Furkan Erdem 1-1/+1 2024-02-23Fix(node): Custom headers are not present in responses from standalone Node s...Gravatar Furkan Erdem 8-0/+163