---
title: "Bun v0.4"
description: Introducing bunx. Install and run an executable from npm, 100x faster than npx.
date: "2022-12-23T07:00:00Z"
author: ashcon
thumbText: v0.4.0
shareImage: "https://user-images.githubusercontent.com/3238291/209300634-79333724-1bbc-4c80-a811-23d6e1ff6373.gif"
---

{% callout %}
**Note** — We're [hiring](/careers) C/C++ and Zig engineers to build the future of JavaScript!
{% /callout %}

Happy Holidays! We're excited to release Bun v0.4.0 with support for more Node.js APIs, increased stability, lots of bug fixes, and a new command: `bunx`.

## Introducing `bunx`

This version introduces `bunx`, Bun's equivalent of `npx` with 100x faster startup times. It runs [executables](https://docs.npmjs.com/cli/v9/configuring-npm/package-json#bin) from local or remote npm packages.

```bash
$ bunx esbuild --version
```

As with `npx`, it will check for a locally installed package first, then fall back to auto-installing from npm into a shared global cache. With Bun's fast startup times, it's roughly 100x faster than `npx` for locally installed packages.

{% raw %}

<blockquote class="twitter-tweet"><p lang="en" dir="ltr">Introducing bunx<br><br>auto-install &amp; run an executable from npm<br><br>100x faster than npx<br><br>left: &quot;bunx esbuild --version&quot; (1k runs)<br>right: &quot;npx esbuild --version&quot; (1k runs) <a href="https://t.co/pbgzfXyhnP">pic.twitter.com/pbgzfXyhnP</a></p>&mdash; Jarred Sumner (@jarredsumner) <a href="https://twitter.com/jarredsumner/status/1606163655527059458?ref_src=twsrc%5Etfw">December 23, 2022</a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>

{% /raw %}

## The `--bun` flag

By default, Bun respects the `#!/usr/bin/env node` shebang at the top of scripts or executables that are run with `bun run <script>` or `bunx <command>`.

```ts
// foo.js
#! /usr/bin/env node

console.log(process.argv[0]);
```

```bash
$ bun run foo.js
/path/to/node/19.2.0/bin/node
```

To override this behavior, pass the `--bun` flag. This temporarily aliases `node` to `bun` for the duration of the execution.

```bash
$ bun --bun run foo.js
/path/to/.bun/bin/bun
```

In the future, we might make this behaviour the default once Bun's Node.js compatibility is more complete.

{% image src="https://user-images.githubusercontent.com/709451/209322608-e3eb8201-a0b7-409c-a5e2-076868198f4e.png" height=600 width=600 alt="bun --bun vite" /%}

## Node.js compatibility

Support for Node.js APIs continues to be a top priority for Bun. As of Bun v0.4.0, you can now use the following APIs:

- [`crypto.timingSafeEqual()`](https://nodejs.org/api/crypto.html#cryptotimingsafeequala-b)
- [`crypto.scryptSync()`](https://nodejs.org/api/crypto.html#cryptoscryptsyncpassword-salt-keylen-options)
- [`process.abort()`](https://nodejs.org/api/process.html#processabort)
- [`process.argv0`](https://nodejs.org/api/process.html#processargv0) and [`process.execPath`](https://nodejs.org/api/process.html#processexecpath)
- [`node:util/types`](https://nodejs.org/api/util.html#utiltypes)

## Setup and teardown in `bun:test`

Bun has a built-in test runner that you can run using the command: `bun wiptest`. You can now define [Jest-style](https://jestjs.io/docs/setup-teardown) lifecycle hooks for the setup and teardown of tests.

```js
import { beforeAll, test } from "bun:test";

let tests;
beforeAll(async () => {
  const response = await fetch("https://example.com/path/to/resource");
  tests = await response.json();
});

test("that integration tests are defined", () => {
  expect(tests).toHaveLength(100);
});
```

## `Bun.deepEquals()` strict

You can now pass a `strict` argument to `Bun.deepEquals()`, which will have the same behaviour as [`expect().toStrictEqual()`](https://jestjs.io/docs/expect#tostrictequalvalue).

```js
const a = { entries: [1, 2] };
const b = { entries: [1, 2], extra: undefined };

Bun.deepEquals(a, b); // => true
Bun.deepEquals(a, b, true); // => false
```

## `bun pm`

In case you missed it, Bun has a command that allows you see information about your packages and lockfile in a project: `bun pm`.

![Output of "bun pm"](https://user-images.githubusercontent.com/3238291/209288829-d2efc679-6bea-4018-9b33-3aa8024b12eb.png)

### `bun pm ls`

In Bun v0.4.0 there is new sub-command, `bun pm ls`, which will list all the packages and versions in your project, similar to `npm ls`.

![Output of "bun pm ls"](https://user-images.githubusercontent.com/3238291/209293604-53d81cb7-1b80-437b-8d11-a760f9986b2c.png)

## Notable Fixes

- Fixed various issues when installing dependencies - [`#1643`](https://github.com/oven-sh/bun/pull/1643), [`#1647`](https://github.com/oven-sh/bun/pull/1647), [`#1649`](https://github.com/oven-sh/bun/pull/1649)
- Fixed various bugs with [`node:stream`](https://nodejs.org/api/stream.html#stream) - [`#1606`](https://github.com/oven-sh/bun/pull/1606), [`#1613`](https://github.com/oven-sh/bun/pull/1613)
- Fixed [`process.stdin`](https://nodejs.org/api/process.html#processstdin) not working in a `tty` - [`#1611`](https://github.com/oven-sh/bun/pull/1611), [`#1626`](https://github.com/oven-sh/bun/pull/1626)
- Fixed [`Bun.write()`](https://github.com/oven-sh/bun#bunwrite--optimizing-io) on older Linux kernels that don’t support `io_uring` - [`e7a14f8`](https://github.com/oven-sh/bun/commit/e7a14f857d74fc6d61dad4414f01d8621ecc8262)
- Fixed an issue when importing a binary file - [`5bbaa7`](https://github.com/oven-sh/bun/commit/5bbaa7b400eee69669f0cd65d0ee5d26143c4910)
- Fixed a transpiler bug where `const {resolve} = require` would not work - [`3c2029`](https://github.com/oven-sh/bun/commit/3c20290e492deb3b9c73b639f15fb395ff2934f7)
- Implemented support for passing arguments to [`setTimeout()`](https://developer.mozilla.org/en-US/docs/Web/API/setTimeout), [`setInterval()`](https://developer.mozilla.org/en-US/docs/Web/API/setInterval), and [`setImmediate()`](https://developer.mozilla.org/en-US/docs/Web/API/Window/setImmediate) - [`a98e0ad`](https://github.com/oven-sh/bun/commit/a98e0adc7dda63600ff811fc6928c69879334dc5)
- Removed a work-around for RegExp backtracking support, since WebKit implemented it - [`#1625`](https://github.com/oven-sh/bun/pull/1625)
- Fixed a transpiler bug (in Bun) breaking `@babel/parser` when loading in Bun's runtime

## PR log

- fix `__require` collision from linking by [@dylan-conway](https://github.com/dylan-conway) in https://github.com/oven-sh/bun/pull/1585
- chore: add eslintcache by [@Simon-He95](https://github.com/Simon-He95) in https://github.com/oven-sh/bun/pull/1586
- Add filename completions on `bun` command to Zsh by [@colinhacks](https://github.com/colinhacks) in https://github.com/oven-sh/bun/pull/1593
- Exclude additional TSdeclaration file extensions from completions by [@colinhacks](https://github.com/colinhacks) in https://github.com/oven-sh/bun/pull/1596
- fix path string by [@YUxiangLuo](https://github.com/YUxiangLuo) in https://github.com/oven-sh/bun/pull/1597
- override `process.stdin.on()` correctly by [@alexlamsl](https://github.com/alexlamsl) in https://github.com/oven-sh/bun/pull/1603
- fix(stream): Fix Readable.pipe() by [@ThatOneBro](https://github.com/ThatOneBro) in https://github.com/oven-sh/bun/pull/1606
- make `process.stdin` work under TTY by [@alexlamsl](https://github.com/alexlamsl) in https://github.com/oven-sh/bun/pull/1611
- add `bun pm ls` for printing lockfiles by [@dylan-conway](https://github.com/dylan-conway) in https://github.com/oven-sh/bun/pull/1612
- fix(stream): make Readable.read work w/o \_construct implemented by [@ThatOneBro](https://github.com/ThatOneBro) in https://github.com/oven-sh/bun/pull/1613
- Fix typo in bun.d.ts by [@eltociear](https://github.com/eltociear) in https://github.com/oven-sh/bun/pull/1619
- add tests for `process.stdin` by [@alexlamsl](https://github.com/alexlamsl) in https://github.com/oven-sh/bun/pull/1621
- docs(README.md): update bun-types new path definition by [@hoseinprd](https://github.com/hoseinprd) in https://github.com/oven-sh/bun/pull/1622
- Delete Oniguruma by [@Jarred-Sumner](https://github.com/Jarred-Sumner) in https://github.com/oven-sh/bun/pull/1625
- bug compatible with `stdin.on("readable")` by [@alexlamsl](https://github.com/alexlamsl) in https://github.com/oven-sh/bun/pull/1626
- Implement `bunx` by [@Jarred-Sumner](https://github.com/Jarred-Sumner) in https://github.com/oven-sh/bun/pull/1634
- add tests for #1633 by [@alexlamsl](https://github.com/alexlamsl) in https://github.com/oven-sh/bun/pull/1635
- fix jest hooks in bun-test by [@ethanburrell](https://github.com/ethanburrell) in https://github.com/oven-sh/bun/pull/1639
- fix `bun install` dependency resolution by [@alexlamsl](https://github.com/alexlamsl) in https://github.com/oven-sh/bun/pull/1643
- [install] avoid dependency conflicts between siblings by [@alexlamsl](https://github.com/alexlamsl) in https://github.com/oven-sh/bun/pull/1647
- Update benchmarks by [@colinhacks](https://github.com/colinhacks) in https://github.com/oven-sh/bun/pull/1648
- [install] fix remaining corner cases with dependency resolution by [@alexlamsl](https://github.com/alexlamsl) in https://github.com/oven-sh/bun/pull/1649

## Contributors

We'd also like to thank everyone who helped contribute to Bun.

- [alexlamsl](https://github.com/oven-sh/bun/commits?author=alexlamsl&since=2022-12-07&until=2022-12-22) for fixing issues with `process`, `node:stream`, and `bun install`
- [ThatOneBro](https://github.com/oven-sh/bun/commits?author=ThatOneBro&since=2022-12-07&until=2022-12-22) for fixing issues with `node:stream`
- [ethanburrell](https://github.com/oven-sh/bun/commits?author=ethanburrell&since=2022-12-07&until=2022-12-22) for fixing support for lifecycle hooks in `bun:test`
- [hoseinprd](https://github.com/oven-sh/bun/commits?author=hoseinprd&since=2022-12-07&until=2022-12-22), [eltociear](https://github.com/oven-sh/bun/commits?author=eltociear&since=2022-12-07&until=2022-12-22), [YUxiangLuo](https://github.com/oven-sh/bun/commits?author=YUxiangLuo&since=2022-12-07&until=2022-12-22), and [Simon-He95](https://github.com/oven-sh/bun/commits?author=Simon-He95&since=2022-12-07&until=2022-12-22) for contributing to Bun
