DEV Community

Alex Spinov
Alex Spinov

Posted on

Bun Has a Free Ultra-Fast JavaScript Runtime and Toolkit

Bun is a free, all-in-one JavaScript runtime, bundler, transpiler, and package manager. It is significantly faster than Node.js and Deno.

What Is Bun?

Bun is a drop-in Node.js replacement built from scratch using Zig and JavaScriptCore (Safari engine) for maximum performance.

Key features:

  • 4x faster than Node.js startup
  • Built-in bundler (replaces webpack/esbuild)
  • Built-in test runner (replaces Jest)
  • Built-in package manager (replaces npm, 25x faster)
  • Native TypeScript and JSX
  • Node.js compatible
  • SQLite built-in
  • Web-standard APIs

Quick Start

# Install
curl -fsSL https://bun.sh/install | bash

# Run TypeScript directly
bun run server.ts

# Install packages (25x faster than npm)
bun install
Enter fullscreen mode Exit fullscreen mode

HTTP Server

Bun.serve({
  port: 3000,
  fetch(req) {
    const url = new URL(req.url);
    if (url.pathname === "/api/data") {
      return Response.json({ status: "ok", timestamp: Date.now() });
    }
    return new Response("Not Found", { status: 404 });
  }
});
Enter fullscreen mode Exit fullscreen mode

Package Manager Speed

# Install all dependencies
bun install  # ~0.5 seconds (vs npm: ~15 seconds)

# Add package
bun add express  # instant
Enter fullscreen mode Exit fullscreen mode

Built-in SQLite

import { Database } from "bun:sqlite";

const db = new Database("app.db");
db.run("CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT, email TEXT)");
db.run("INSERT INTO users (name, email) VALUES (?, ?)", ["Alice", "alice@email.com"]);

const users = db.query("SELECT * FROM users").all();
console.log(users);
Enter fullscreen mode Exit fullscreen mode

Built-in Test Runner

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

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

test("async fetch", async () => {
  const res = await fetch("https://api.github.com");
  expect(res.status).toBe(200);
});
Enter fullscreen mode Exit fullscreen mode
bun test  # Runs tests instantly
Enter fullscreen mode Exit fullscreen mode

Bun vs Node.js vs Deno

Feature Node.js Deno Bun
Startup time 40ms 30ms 7ms
Package install Slow (npm) Moderate 25x faster
TypeScript Config needed Native Native
Bundler External No Built-in
Test runner External Built-in Built-in
SQLite External External Built-in
npm compat Native Yes Yes

Bundler

bun build ./src/index.ts --outdir ./dist --minify
Enter fullscreen mode Exit fullscreen mode

Replaces webpack, esbuild, rollup. Built-in.

With 78K+ GitHub stars. The fastest JavaScript runtime.


Building fast scrapers? Check out my web scraping tools on Apify. Custom solutions: spinov001@gmail.com

Top comments (0)