Files
bun.sh/docs/runtime/index.md
2025-08-23 18:54:50 -07:00

10 KiB

Bun is a new JavaScript & TypeScript runtime designed to be a faster, leaner, and more modern drop-in replacement for Node.js.

Speed

Bun is designed to start fast and run fast. Its transpiler and runtime are written in Zig, a modern, high-performance language. On Linux, this translates into startup times 4x faster than Node.js.

{% image src="/images/bun-run-speed.jpeg" caption="Bun vs Node.js vs Deno running Hello World" /%}

Performance sensitive APIs like Buffer, fetch, and Response are heavily profiled and optimized. Under the hood Bun uses the JavaScriptCore engine, which is developed by Apple for Safari. It starts and runs faster than V8, the engine used by Node.js and Chromium-based browsers.

TypeScript

Bun natively supports TypeScript out of the box. All files are transpiled on the fly by Bun's fast native transpiler before being executed. Similar to other build tools, Bun does not perform typechecking; it simply removes type annotations from the file.

$ bun index.js
$ bun index.jsx
$ bun index.ts
$ bun index.tsx

Some aspects of Bun's runtime behavior are affected by the contents of your tsconfig.json file. Refer to Runtime > TypeScript page for details.

JSX

JSON, TOML, and YAML

Source files can import *.json, *.toml, or *.yaml files to load their contents as plain JavaScript objects.

import pkg from "./package.json";
import bunfig from "./bunfig.toml";
import config from "./config.yaml";

See the YAML API documentation for more details on YAML support.

WASI

{% callout %} 🚧 Experimental {% /callout %}

Bun has experimental support for WASI, the WebAssembly System Interface. To run a .wasm binary with Bun:

$ bun ./my-wasm-app.wasm
# if the filename doesn't end with ".wasm"
$ bun run ./my-wasm-app.whatever

{% callout %}

Note — WASI support is based on wasi-js. Currently, it only supports WASI binaries that use the wasi_snapshot_preview1 or wasi_unstable APIs. Bun's implementation is not fully optimized for performance; this will become more of a priority as WASM grows in popularity. {% /callout %}

Node.js compatibility

Long-term, Bun aims for complete Node.js compatibility. Most Node.js packages already work with Bun out of the box, but certain low-level APIs like dgram are still unimplemented. Track the current compatibility status at Ecosystem > Node.js.

Bun implements the Node.js module resolution algorithm, so dependencies can still be managed with package.json, node_modules, and CommonJS-style imports.

{% callout %} Note — We recommend using Bun's built-in package manager for a performance boost over other npm clients. {% /callout %}

Web APIs

Some Web APIs aren't relevant in the context of a server-first runtime like Bun, such as the DOM API or History API. Many others, though, are broadly useful outside of the browser context; when possible, Bun implements these Web-standard APIs instead of introducing new APIs.

The following Web APIs are partially or completely supported.

{% table %}

















{% /table %}

Bun APIs

Bun exposes a set of Bun-specific APIs on the Bun global object and through a number of built-in modules. These APIs represent the canonical "Bun-native" way to perform some common development tasks. They are all heavily optimized for performance. Click the link in the left column to view the associated documentation.

{% table %}

  • Topic
  • APIs




  • TCP
  • Bun.listen Bun.connect




  • Utils
  • Bun.peek Bun.which






{% /table %}

Plugins

Support for additional file types can be implemented with plugins. Refer to Runtime > Plugins for full documentation.