Bun
Complete reference for Bun — the all-in-one JavaScript/TypeScript runtime, package manager, bundler, and test runner
Installation & Setup
Install Bun and configure your project
Install & Initialize
Install Bun and scaffold a new project
bunfig.toml Configuration
Configure Bun behavior with the bunfig.toml config file
Running Scripts & Files
Execute files, scripts, and packages with bun run and bunx
bun run & bunx
Run files, package.json scripts, and remote packages
Package Manager
Install, manage, and publish packages with bun install
Managing Dependencies
Install, add, remove, and update packages
HTTP Server
Build high-performance HTTP servers with Bun.serve()
Bun.serve() Basics
Create an HTTP server with routes and request handling
WebSockets
Built-in WebSocket server support with pub/sub messaging
WebSocket Server
Add WebSocket support to Bun.serve with handlers and pub/sub
File I/O
Read, write, and manipulate files with Bun.file() and Bun.write()
Reading & Writing Files
Fast file operations with Bun.file() and Bun.write()
SQLite & Database
Built-in SQLite database with the bun:sqlite module
bun:sqlite
Use the built-in SQLite database for fast local storage
Test Runner
Jest-compatible testing with bun test
Writing & Running Tests
Write Jest-compatible tests with describe, test, and expect
Mocks & Snapshots
Mock functions, spy on methods, and use snapshot testing
Bundler
Bundle JavaScript, TypeScript, and CSS with bun build
bun build
Bundle code for browsers and servers
Programmatic Bundler API
Use Bun.build() in code with plugins and advanced options
Shell & Child Processes
Run shell commands with Bun.$ and spawn child processes
Bun Shell ($)
Run shell commands with tagged template literals
Bun.spawn()
Spawn child processes with fine-grained control
Environment & Utilities
Environment variables, hashing, passwords, and built-in utilities
Environment Variables
Access and manage environment variables with auto .env loading
Hashing & Passwords
Built-in hashing and secure password operations
Workers & Concurrency
Run code in parallel with Web Workers and Bun-specific APIs
Web Workers
Run CPU-intensive tasks in parallel threads