>_cat bun.md|Web & App Servers
Index

Bun Cheatsheet

SPEC: MDX·/bun·HTTP reverse proxies, application runtimes, and log analysis.

Bun is an incredibly fast, all-in-one JavaScript runtime and toolkit designed as a drop-in replacement for Node.js, built from scratch using the Zig language and Apple's WebKit JavaScriptCore engine.

Installation

Linux / macOS

curl -fsSL https://bun.sh/install | bash
source ~/.bashrc   # or source ~/.zshrc

Windows (PowerShell)

powershell -c "irm bun.sh/install.ps1 | iex"

Via Package Managers

# Homebrew (macOS / Linux)
brew install oven-sh/bun/bun
 
# npm (standalone binary wrapper)
npm install -g bun

Upgrading Bun

bun upgrade

Runtime (Execute JS & TS)

Bun natively executes JavaScript, TypeScript, and JSX without requiring configuration or compilation steps.

bun run app.ts                     # Run TypeScript directly
bun run index.js                   # Run JavaScript file
bun run dev                        # Execute "dev" script from package.json
bun --watch app.ts                 # Auto-restart on file changes
bun --hot server.ts                # Hot reload code without restarting process
bun repl                           # Open interactive terminal REPL

Package Manager (bun install)

Bun is designed to be 10x-30x faster than npm and yarn when resolving and linking dependencies.

Installing Dependencies

bun install                        # Install dependencies from package.json (fast)
bun install --production           # Install only production dependencies
bun install --frozen-lockfile      # Strict install for CI/CD pipelines

Adding & Removing Packages

bun add express                    # Add production dependency
bun add -d @types/node             # Add dev dependency (--dev)
bun add -g pm2                     # Install global package
bun remove lodash                  # Remove package
bun update                         # Update dependencies
bun pm cache rm                    # Clear global module cache

Running Scripts & Binaries (bunx)

bunx is the high-speed alternative to npx.

bunx create-next-app@latest        # Run package binary without global install
bunx prisma studio
bunx tailwindcss init

Testing (bun test)

Bun includes a fast, Jest-compatible test runner built directly into the binary.

bun test                           # Run all test files (*.test.ts, *.spec.js)
bun test --watch                   # Run tests in watch mode
bun test auth.test.ts              # Run a specific test file
bun test -t "user login"           # Run tests matching description filter

Bundling & Building

# Bundle frontend app into a single output file
bun build ./src/index.ts --outdir ./dist
 
# Compile standalone single-binary executable
bun build ./cli.ts --compile --outfile my-cli

Quick Reference

CommandPurpose
bun run app.tsExecute file (TS/JS native)
bun installHigh-speed dependency installation
bun add pkgAdd dependency to package.json
bunx pkgRun binary (fast npx replacement)
bun testExecute built-in Jest-compatible tests
bun --watchRestart on code changes