>_cat bun.md|Web & App Servers
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 ~/.zshrcWindows (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 bunUpgrading Bun
bun upgradeRuntime (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 REPLPackage 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 pipelinesAdding & 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 cacheRunning 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 initTesting (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 filterBundling & 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-cliQuick Reference
| Command | Purpose |
|---|---|
bun run app.ts | Execute file (TS/JS native) |
bun install | High-speed dependency installation |
bun add pkg | Add dependency to package.json |
bunx pkg | Run binary (fast npx replacement) |
bun test | Execute built-in Jest-compatible tests |
bun --watch | Restart on code changes |