Bun — A fast all-in-one JavaScript runtime

Bun is joining Anthropic & Anthropic is betting on Bun →

Bun is a fast, incrementally adoptable all-in-one JavaScript, TypeScript & JSX toolkit. Use individual tools like bun test or bun install in Node.js projects, or adopt the complete stack with a fast JavaScript runtime, bundler, test runner, and package manager built in. Bun aims for 100% Node.js compatibility.

Bundling 10,000 React components

Build time in milliseconds (Linux x64, Hetzner)

Express.js 'hello world'

HTTP requests per second (Linux x64)

  • bun: 59,026 requests per second

  • deno: 25,335 requests per second

  • node: 19,039 requests per second

View benchmark →

WebSocket chat server

Messages sent per second (Linux x64, 32 clients)

  • bun: 2,536,227 messages sent per second

  • deno: 1,320,525 messages sent per second

  • node: 435,099 messages sent per second

View benchmark →

Load a huge table

Queries per second. 100 rows x 100 parallel queries

  • bun: 28,571 queries per second

  • node: 14,522 queries per second

  • deno: 11,169 queries per second

View benchmark →

Use them together as an all-in-one toolkit, or adopt them incrementally. bun test works in Node.js projects. bun install can be used as the fastest npm client. Each tool stands on its own.

Who uses Bun?

Bun's all-in-one toolkit makes Railway's serverless functions fast and easy to use.

Deploy on Railway

What's different about Bun?

Bun provides extensive builtin APIs and tooling

Builtin Core Features

Essential runtime capabilities

Bun

Bun

Node

Deno

Node.js compatibility

Aiming to be a drop-in replacement for Node.js apps

Web Standard APIs

Support for web standard APIs like fetch, URL, EventTarget, Headers, etc.

Powered by WebCore (from WebKit/Safari)

Native Addons

Call C-compatible native code from JavaScript

Bun.ffi, NAPI, partial V8 C++ API

TypeScript

First-class support, including "paths" enum namespace

JSX

First-class support without configuration

Module loader plugins

Plugin API for importing/requiring custom file types

`Bun.plugin` works in browsers & Bun

3 different loader APIs. Server-side only

Builtin APIs

Built-in performance and native APIs designed for production

Bun

Bun

Node

Deno

PostgreSQL, MySQL, and SQLite drivers

Connect to any SQL database with one fast, unified API

Fastest available, with query pipelining

S3 Cloud Storage driver

Upload and download from S3-compatible storage, built-in

Fastest available

Redis client

Redis client built into Bun with Pub/Sub support

WebSocket server (including pub/sub)

WebSocket server built into Bun.serve() with backpressure handling

`Bun.serve()`

HTTP server

Lightning-fast HTTP server built into Bun

Bun.serve()

HTTP router

Route HTTP requests with dynamic paths and wildcards, built into Bun.serve()

Bun.serve({routes: {'/api/:path': (req) => { ... }}}})

Single-file executables

Compile your app to a standalone executable that runs anywhere

bun build --compile with cross-compilation & code signing

No native addons, embedded files, cross-compilation or bytecode. Multi-step process.

No native addons, no cross-compilation

YAML

YAML is a first-class citizen in Bun, just like JSON

Bun.YAML & import from .yaml files

Cookies API

Parse and set cookies with zero overhead using a Map-like API

request.cookies Map-like API

Encrypted Secrets Storage

Store secrets securely using your OS's native keychain

Bun.secrets (Keychain/libsecret/Windows Credential Manager)

Builtin Tooling

Built-in developer tooling

Bun

Bun

Node

Deno

npm package management

Install, manage, and publish npm-compatible dependencies

With catalogs, isolated installs, bun audit, bun why

Limited features

Bundler

Build production-ready code for frontend & backend

Bun.build

Cross-platform $ shell API

Native bash-like shell for cross-platform shell scripting

`Bun.$`

Requires 'dax'

Jest-compatible test runner

Testing library compatible with the most popular testing framework

bun test with VS Code integration & concurrent execution

Hot reloading (server)

Reload your backend without disconnecting connections, preserving state

bun --hot

Monorepo support

Install workspaces packages and run commands across workspaces

bun run --filter=package-glob ...

Frontend Development Server

Run modern frontend apps with a fully-featured dev server

bun ./index.html

Formatter & Linter

Built-in formatter and linter

Builtin Utilities

APIs that make your life easier as a developer

Bun

Bun

Node

Deno

Password & Hashing APIs

bcrypt, argon2, and non-cryptographic hash functions

`Bun.password` & `Bun.hash`

String Width API

Calculate the width of a string as displayed in the terminal

Bun.stringWidth

Glob API

Glob patterns for file matching

Bun.Glob

fs.promises.glob

Semver API

Compare and sort semver strings

Bun.semver

CSS color conversion API

Convert between CSS color formats

Bun.color

CSRF API

Generate and verify CSRF tokens

Bun.CSRF

Everything you need to build & ship

Production-ready APIs and tools, built into Bun

Bun is a new JavaScript runtime built from scratch to serve the modern JavaScript ecosystem. It has three major design goals:

  • Bun starts fast and runs fast. It extends JavaScriptCore, the performance-minded JS engine built for Safari. Fast start times mean fast apps and fast APIs.
  • Bun provides a minimal set of highly-optimized APIs for performing common tasks, like starting an HTTP server and writing files.
  • Bun is a complete toolkit for building JavaScript apps, including a package manager, test runner, and bundler.

Bun is designed as a drop-in replacement for Node.js. It natively implements thousands of Node.js and Web APIs, including fs, path, Buffer and more.

The goal of Bun is to run most of the world's server-side JavaScript and provide tools to improve performance, reduce complexity, and multiply developer productivity.

Bun works with Next.js

Full speed full-stack

Fast frontend apps with Bun's built-in high performance development server and production bundler. You've never seen hot-reloading this fast!

Develop and ship frontend apps

Bun's built-in bundler and dev server make frontend development fast and simple. Develop with instant hot reload, then ship optimized production builds—all with zero configuration.

Start a dev server

Run bun ./index.html to start a dev server. TypeScript, JSX, React, and CSS imports work out of the box.

Hot Module Replacement

Built-in HMR preserves application state during development. Changes appear instantly—no manual refresh needed.

Build for production

Build optimized bundles with bun build ./index.html --production. Tree-shaking, minification, and code splitting work out of the box.

Installing dependencies from cache for a Remix app.
View benchmark

Replace yarn with bun install to get 30x faster package installs.

Replace jest with bun test to run your tests 10-30x faster.

Start an HTTP server

Start a WebSocket server

Read and write files

Hash a password

Frontend dev server

Write a test

Query PostgreSQL

Use Redis

Import YAML

Set cookies

Run a shell script

Call a C function

index.tsx

import { sql, serve } from "bun";

const server = serve({
  port: 3000,
  routes: {
    "/": new Response("Welcome to Bun!"),
    "/api/users": async (req) => {
      const users = await sql`SELECT * FROM users LIMIT 10`;
      return Response.json({ users });
    },
  },
});

console.log(`Listening on localhost:${server.port}`);

index.tsx

const server = Bun.serve<{ authToken: string; }>({
  fetch(req, server) {
    // use a library to parse cookies
    const cookies = parseCookies(req.headers.get("Cookie"));
    server.upgrade(req, {
      data: { authToken: cookies['X-Token'] },
    });
  },
  websocket: {
    // handler called when a message is received
    async message(ws, message) {
      console.log(`Received: ${message}`);
      const user = getUserFromToken(ws.data.authToken);
      await db.Message.insert({
        message: String(message),
        userId: user.id,
      });
    },
  },
});

console.log(`Listening on localhost:${server.port}`);

index.tsx

const file = Bun.file(import.meta.dir + '/package.json'); // BunFile

const pkg = await file.json(); // BunFile extends Blob
pkg.name = 'my-package';
pkg.version = '1.0.0';

await Bun.write(file, JSON.stringify(pkg, null, 2));

index.tsx

const password = "super-secure-pa$$word";

const hash = await Bun.password.hash(password);
// => $argon2id$v=19$m=65536,t=2,p=1$tFq+9AVr1bfPxQdh...

const isMatch = await Bun.password.verify(password, hash);
// => true

server.ts

// Run 'bun init --react' to get started
import { serve } from "bun";
import reactApp from "./index.html";

serve({
  port: 3000,
  routes: {
    "/": reactApp,
    "/api/hello": () => Response.json({ message: "Hello!" }),
  },
  development: {
    console: true, // Stream browser logs to terminal
    hmr: true, // Enable hot module reloading
  },
});

index.test.tsx

import { test, expect } from "bun:test";

// Run tests concurrently for better performance
test.concurrent("fetch user 1", async () => {
  const res = await fetch("https://api.example.com/users/1");
  expect(res.status).toBe(200);
});

test.concurrent("fetch user 2", async () => {
  const res = await fetch("https://api.example.com/users/2");
  expect(res.status).toBe(200);
});

test("addition", () => {
  expect(2 + 2).toBe(4);
});

index.tsx

import { sql } from "bun";

// Query with automatic SQL injection prevention
const users = await sql`
  SELECT * FROM users
  WHERE active = ${true}
  LIMIT 10
`;

// Insert with object notation
const [user] = await sql`
  INSERT INTO users ${sql({
    name: "Alice",
    email: "alice@example.com"
  })}
  RETURNING *
`;

config.yaml

// Import YAML files directly
import config from "./config.yaml";

console.log(config.database.host);
// => "localhost"

// Or parse YAML at runtime
const data = Bun.YAML.parse(`
name: my-app
version: 1.0.0
database:
  host: localhost
  port: 5432
`);

index.tsx

import { serve } from "bun";

serve({
  port: 3000,
  routes: {
    "/": (request) => {
      // Read cookies with built-in parsing
      const sessionId = request.cookies.get("session_id");

      // Set cookies
      request.cookies.set("session_id", "abc123", {
        path: "/",
        httpOnly: true,
        secure: true,
      });

      return Response.json({ success: true });
    },
  },
});

index.tsx

import { redis } from "bun";

// Set a key
await redis.set("greeting", "Hello from Bun!");

console.log(db.query("SELECT 1 as x").get());
// { x: 1 }

index.tsx

import { $ } from 'bun';

// Run a shell command (also works on Windows!)
await $`echo "Hello, world!"`;

const response = await fetch("https://example.com");

// Pipe the response body to gzip
const data = await $`gzip < ${response}`.arrayBuffer();

index.tsx

import { dlopen, FFIType, suffix } from "bun:ffi";

// `suffix` is either "dylib", "so", or "dll" depending on the platform
const path = `libsqlite3.${suffix}`;

const {
  symbols: {
    sqlite3_libversion, // the function to call
  },
} = dlopen(path, {
  sqlite3_libversion: {
    args: [], // no arguments
    returns: FFIType.cstring, // returns a string
  },
});

console.log(`SQLite 3 version: ${sqlite3_libversion()}`);