mcpField
B
bun

bun

github.com/itechmeatDevelopment2388 installsUpdated 2w ago
Repository

About bun

bun is an all-in-one JavaScript and TypeScript toolkit for developers, combining a runtime, package manager, test runner, and bundler. It also includes APIs for tasks such as HTTP serving, storage, and database access.

Key features

  1. 01JavaScript and TypeScript runtime
  2. 02Package installation and management
  3. 03Built-in test runner and bundler
  4. 04HTTP and WebSocket APIs
  5. 05SQLite, S3, and Redis access

Use cases

  1. 01Run TypeScript without a separate build step
  2. 02Install and maintain project dependencies
  3. 03Test and bundle JavaScript projects
  4. 04Build services using HTTP or WebSockets

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/itechmeat/llm-code --skill bun

After installing, type/bunin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

references/
bunfig.md
cc.md
development.md
env.md
fetch.md
file-io.md
file-system-router.md
http-server.md
module-system.md
native-interop.md
networking-low-level.md
nodejs-compat.md
package-manager.md
plugins.md
project-scaffolding.md
redis.md
s3.md
shell.md
spawn.md
sqlite.md
transpiler.md
typescript-jsx.md
utilities.md
websockets.md
webview.md
workers.md

Details

From the project README

Bun

All-in-one JavaScript/TypeScript toolkit: runtime, package manager, test runner, bundler.

Quick Navigation

TopicReference
Package Managerreferences/package-manager.md
Project Setupreferences/project-scaffolding.md
Developmentreferences/development.md
Module Systemreferences/module-system.md
TypeScript & JSXreferences/typescript-jsx.md
Configurationreferences/bunfig.md
HTTP Serverreferences/http-server.md
Browser Automationreferences/webview.md
WebSocketsreferences/websockets.md
File I/Oreferences/file-io.md
SQLitereferences/sqlite.md
S3 Storagereferences/s3.md
Redisreferences/redis.md
Low-Level Networkreferences/networking-low-level.md
Fetch APIreferences/fetch.md
Shell Scriptsreferences/shell.md
Spawn Processreferences/spawn.md
Workersreferences/workers.md
Native FFIreferences/native-interop.md
C/C++ Compilereferences/cc.md
Transpilerreferences/transpiler.md
Pluginsreferences/plugins.md
FS Routerreferences/file-system-router.md
Environment Varsreferences/env.md
Utilitiesreferences/utilities.md
Node.js Compatreferences/nodejs-compat.md

When to Use Bun

  • Running TypeScript/JSX without build step
  • Fast HTTP server with native routing
  • Headless browser automation with native input events
  • SQLite database (embedded, no deps)
  • WebSocket server/client
  • S3-compatible storage (AWS, R2, MinIO)
  • Redis caching/pub-sub
  • Cross-platform shell scripts
  • In-process cron scheduling
  • Markdown parsing (v1.3.8+)
  • Native library calls via FFI

Core Advantages

  • 4x faster startup than Node.js
  • Native TypeScript/JSX — no tsconfig needed
  • ESM + CommonJS — both work seamlessly
  • Web APIs built-in — fetch, WebSocket, etc.
  • 30x faster installs than npm

Quick Start

# Run TypeScript directly
bun run index.ts

# Install packages
bun install

# Run package.json script
bun run dev

# Execute package binary
bunx cowsay "Hello"

# Run tests
bun test

# Build for production
bun build ./index.ts --outdir ./dist

# Bundle analysis for LLMs (v1.3.8+)
bun build ./index.ts --metafile-md --outdir ./dist

Critical Rules

Don'tDo
http.createServer()Bun.serve()
fs.readFileSync()Bun.file().text()
better-sqlite3bun:sqlite
child_process.exec()Bun.$ or Bun.spawn()
dotenvBuilt-in .env support

Release Highlights (1.4.x)

  • Rust rewrite: first release of the Rust port. Lower peak memory (mimalloc allocator, 13-48% less under load), ~2x faster startup, 5x lower idle CPU, and 1,500+ more passing Node.js test-suite tests.
  • HTTP/2 & HTTP/3: Bun.serve() serves HTTP/1.1 and HTTP/2 on the same port via ALPN over TLS (v1.4.1); HTTP/3 is experimental via http3: true. fetch() can use HTTP/2/3 clients behind feature flags.
  • Serve static directories: routes: { "/static/*": { dir: "./public" } } with sendfile, ETag, Range, conditional requests, and index.html.
  • CLI: bun run --parallel for concurrent scripts; bun audit fix, bun dedupe, bun prune, bun pm diff, bun pm licenses for package maintenance.
  • bun test: --parallel, --isolate, --shard=M/N, --timings, --changed (diff-based), --retry, and jest.useFakeTimers().
  • bun build: built-in React Compiler (--react-compiler), barrel-import optimization, tree-shaking through export * as and dynamic import(), --min-chunk-size, and module preloading.
  • bun install: --linker=isolated global virtual store, --offline / --prefer-offline, bun add --catalog, nested overrides, and selfContained workspaces.
  • New runtime APIs: Bun.Terminal (PTY), Bun.Archive (tar), Bun.JSON5/JSONL/JSONC/XML/TOML parsers, streaming Bun.write(path, response), WebSocket.pause()/resume(), crypto.argon2, and post-quantum ML-DSA/ML-KEM in crypto.subtle.

Release Highlights (1.3.14)

  • Bun.Image: built-in image decoding, transforms, and encoding for common formats with no npm dependency or native addon build step.
  • Test workflow: the 1.3.13 line improves dependency-aware filtering for changed-file test runs, which matters when you rely on partial local verification.
  • Patch-line runtime work: 1.3.13-1.3.14 continues compatibility and performance work on top of the 1.3.12 WebView/cron/Markdown release line.

Release Highlights (1.3.12)

  • Bun.WebView: native headless browser automation with WebKit on macOS and Chrome/Chromium via CDP on all platforms.
  • Bun.cron() callback mode: in-process scheduler with no-overlap execution, UTC semantics, hot-reload cleanup, and Disposable job handles.
  • Markdown in terminal: bun ./file.md and Bun.markdown.ansi() make terminal-native rendering a first-class workflow.
  • Networking/runtime: UDP error/truncation handling, Node-compatible unix-socket lifecycle, proxy tunnel reuse, and Bun.serve() accept/perf improvements.

Essential Recipes

HTTP Server
Bun.serve({
  port: 3000,
  fetch(req) {
    const url = new URL(req.url);
    if (url.pathname === "/api/data") {
      return Response.json({ ok: true });
    }
    return new Response("Not Found", { status: 404 });
  },
});
File Operations
// Read
const content = await Bun.file("data.txt").text();

// Write
await Bun.write("output.txt", "Hello World");

// JSON
const config = await Bun.file("config.json").json();
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)");

const insert = db.prepare("INSERT INTO users (name) VALUES (?)");
insert.run("Alice");

const users = db.query("SELECT * FROM users").all();
WebSocket Server
Bun.serve({
  fetch(req, server) {
    if (server.upgrade(req)) return;
    return new Response("Upgrade failed", { status: 400 });
  },
  websocket: {
    message(ws, message) {
      ws.send(`Echo: ${message}`);
    },
  },
});
Shell Commands
import { $ } from "bun";

// Simple command
const files = await $`ls -la`.text();

// With variables (auto-escaped)
const name = "my file.txt";
await $`cat ${name}`;

// Piping
await $`cat data.csv | grep "pattern" | wc -l`;
S3 Storage
import { s3 } from "bun";

// Upload
await s3.file("uploads/doc.pdf").write(data);

// Download
const content = await s3.file("uploads/doc.pdf").text();

// Presigned URL
const url = s3.presign("uploads/doc.pdf", { expiresIn: 3600 });
Redis
import { redis } from "bun";

await redis.set("key", "value");
const value = await redis.get("key");
await redis.expire("key", 3600);
Testing
import { expect, test, describe } from "bun:test";

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

Configuration (bunfig.toml)

[run]
watch = true

[install]
registry = "https://registry.npmjs.org"

[test]
coverage = true

Environment Variables

# .env files loaded automatically
DATABASE_URL=postgres://localhost/mydb
// Access
Bun.env.DATABASE_URL;
process.env.DATABASE_URL;
import.meta.env.DATABASE_URL;

Links

Comments

Markdown supported