Bun is a new JavaScript runtime designed to be a faster, leaner, more modern replacement for Node.js.
Speed
Bun is designed to start fast and run fast. It's transpiler and runtime are written in Zig, a modern, high-performance language. On Linux, this translates into startup times 4x faster than Node.js. 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.
File types
Bun natively supports TypeScript and JSX out of the box.
bun server.tsx
Source files can import a *.json
or *.toml
file to load its contents as a plain old JavaScript object.
import pkg from "./package.json";
import bunfig from "./bunfig.toml";
As of v0.5.2, experimental support has been for the WebAssembly System Interface (WASI), you can run .wasm
binaries.
bun ./my-wasm-app.wasm
# if the filename doesn't end with ".wasm"
bun run ./my-wasm-app.whatever
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 optimized for performance, but if this feature gets popular, we'll definitely invest time in making it faster.
Support for additional file types can be implemented with Plugins.
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.
Note — We recommend using Bun's built-in package manager for a performance boost over other npm clients.
Web-standard
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.
HTTP | fetch Response Request Headers AbortController AbortSignal |
URLs | URL URLSearchParams |
Streams | ReadableStream WritableStream TransformStream ByteLengthQueuingStrategy CountQueuingStrategy and associated classes |
Blob | Blob |
WebSockets | WebSocket |
Encoding and decoding | atob btoa TextEncoder TextDecoder |
Timeouts | setTimeout clearTimeout |
Intervals | setInterval clearInterval |
Crypto | crypto SubtleCrypto CryptoKey |
Debugging | |
Microtasks | queueMicrotask |
Errors | reportError ResolveError BuildError |
User interaction | alert confirm prompt (intended for interactive CLIs) |
Realms | ShadowRealm |
Events | EventTarget Event ErrorEvent CloseEvent MessageEvent |
Bun-native 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.