Bun
Available Resources
Docs
Welcome to Bun: Bun is an all-in-one toolkit for developing modern JavaScript/TypeScript applications.
Installation: Install Bun with npm, Homebrew, Docker, or the official script.
Quickstart: Build your first app with Bun
TypeScript: Using TypeScript with Bun, including type definitions and compiler options
TypeScript 6 and 7: How to configure Bun's type definitions for TypeScript 6.0 and 7.0, which no longer auto-discover @types packages. Fix 'Cannot find name Bun' and other missing type errors after upgrading TypeScript.
bun init: Scaffold an empty Bun project with the interactive
bun initcommandbun create: Create a new Bun project from a React component, a
create-<template>npm package, a GitHub repo, or a local templateBun Runtime: Execute JavaScript/TypeScript files, package.json scripts, and executable packages with Bun's fast runtime.
Watch Mode: Automatic reloading in Bun with --watch and --hot modes
Debugging: Debug your Bun code with an interactive debugger using WebKit Inspector Protocol
REPL: An interactive JavaScript and TypeScript REPL with syntax highlighting, history, and tab completion
bunfig.toml: Configure Bun's behavior using its configuration file bunfig.toml
File Types: File types and loaders supported by Bun's bundler and runtime
Module Resolution: How Bun resolves modules and handles imports in JavaScript and TypeScript
JSX: Built-in JSX and TSX support in Bun with configurable transpilation options
Auto-install: Bun's automatic package installation feature for standalone script execution
Plugins: Universal plugin API for extending Bun's runtime and bundler
File System Router: Bun provides a fast API for resolving routes against file-system paths
Server: Use
Bun.serveto start a high-performance HTTP server in BunRouting: Define routes in
Bun.serveusing static paths, parameters, and wildcardsCookies: Work with cookies in HTTP requests and responses using Bun's built-in Cookie API.
TLS: Enable TLS in Bun.serve
Error Handling: Learn how to handle errors in Bun's development server
Metrics: Monitor server activity with built-in metrics
Fetch: Send HTTP requests with Bun's fetch API
WebSockets: Server-side WebSockets in Bun
TCP: Use Bun's native TCP API to implement performance-sensitive systems like database clients, game servers, or anything that needs to communicate over TCP (instead of HTTP)
UDP: Use Bun's UDP API to implement services with advanced real-time requirements, such as voice chat.
DNS: Use Bun's DNS module to resolve DNS records
Cookies: Use Bun's native APIs for working with HTTP cookies
File I/O: Bun provides a set of optimized APIs for reading and writing files.
Streams: Use Bun's streams API to work with binary data without loading it all into memory at once
Binary Data: Working with binary data in JavaScript
Archive: Create and extract tar archives with Bun's fast native implementation
SQL: Bun provides native bindings for working with SQL databases through a unified Promise-based API that supports PostgreSQL, MySQL, and SQLite.
SQLite: Bun natively implements a high-performance SQLite3 driver.
S3: Bun provides fast, native bindings for interacting with S3-compatible object storage services.
Redis: Use Bun's native Redis client with a Promise-based API
Workers: Use Bun's Workers API to create and communicate with a new JavaScript instance running on a separate thread while sharing I/O resources with the main thread
Environment Variables: Read and configure environment variables in Bun, including automatic .env file support
Shell: Use Bun's shell scripting API to run shell commands from JavaScript
Spawn: Spawn child processes with
Bun.spawnorBun.spawnSyncWebView: Control a headless browser from Bun for automation, testing, and scraping — zero dependencies on macOS, Chrome DevTools Protocol everywhere else
Cron: Schedule and parse cron jobs with Bun
Node-API: Use Bun's Node-API module to build native add-ons to Node.js
FFI: Use Bun's FFI module to efficiently call native libraries from JavaScript
C Compiler: Compile and run C from JavaScript with low overhead
Transpiler: Use Bun's transpiler to transpile JavaScript and TypeScript code
CSRF Protection: Generate and verify CSRF tokens with Bun's built-in API
Secrets: Use Bun's Secrets API to store and retrieve sensitive credentials securely
Console: The console object in Bun
TOML: Use Bun's built-in support for TOML files through both runtime APIs and bundler integration
YAML: Use Bun's built-in support for YAML files through both runtime APIs and bundler integration
Markdown: Parse and render Markdown with Bun's built-in Markdown API, supporting GFM extensions and custom rendering callbacks
JSON5: Use Bun's built-in support for JSON5 files through both runtime APIs and bundler integration
XML: Use Bun's built-in support for XML through both runtime APIs and bundler integration
JSONL: Parse newline-delimited JSON (JSONL) with Bun's built-in streaming parser
HTMLRewriter: Use Bun's HTMLRewriter to transform HTML documents with CSS selectors
Image: Decode, transform, and encode images with a fast native pipeline
Hashing: Utility functions for hashing and verifying passwords with various cryptographically secure algorithms
Glob: Use Bun's fast native implementation of file globbing
Semver: Use Bun's semantic versioning API
Color: Format colors as CSS, ANSI, numbers, hex strings, and more
Utils: Use Bun's utility functions to work with the runtime
Globals: Use Bun's global objects
Bun APIs: Overview of Bun's native APIs available on the Bun global object and built-in modules
Web APIs: Web-standard APIs supported by Bun for server-side JavaScript
Node.js Compatibility: Bun's compatibility status with Node.js APIs, modules, and globals
Roadmap: Bun's roadmap and long-term plans
Benchmarking: How to benchmark Bun
Contributing: Contributing to Bun
Building Windows: Building Bun on Windows
Bindgen: Bindgen for Bun
License: License for Bun
bun install: Install packages with Bun's fast package manager
bun add: Add packages to your project with Bun's fast package manager
bun remove: Remove dependencies from your project
bun update: Update dependencies to the newest versions their ranges allow
bun dedupe: Remove duplicate versions of packages from bun.lock
bun prune: Remove packages that are not in bun.lock from node_modules
bunx: Run packages from npm
bun publish: Use
bun publishto publish a package to the npm registrybun outdated: Check for outdated dependencies
bun why: Explain why a package is installed
bun audit: Check your installed packages for known security vulnerabilities
bun info: Display package metadata from the npm registry
Workspaces: Develop complex monorepos with multiple independent packages
Catalogs: Share common dependency versions across multiple packages in a monorepo
bun link: Link local packages for development
bun pm: Package manager utilities
bun patch: Persistently patch node_modules packages in a git-friendly way
bun --filter: Select packages by pattern in a monorepo using the --filter flag
Global cache: How Bun stores and manages packages in its global cache
Global virtual store: Install packages once. Every project links to the same copy.
Isolated installs: Strict dependency isolation similar to pnpm's approach
Lockfile: Bun's lockfile format and configuration
Lifecycle scripts: How Bun handles package lifecycle scripts securely
Scopes and registries: Configure private registries and scoped packages
Overrides and resolutions: Control metadependency versions with npm overrides and Yarn resolutions
Security Scanner API
.npmrc support
Bundler: Bun's fast native bundler for JavaScript, TypeScript, JSX, and more
Fullstack dev server: Build fullstack applications with Bun's integrated dev server that bundles frontend assets and handles API routes
Hot reloading: Hot Module Replacement (HMR) for Bun's development server
HTML & static sites: Build static sites, landing pages, and web applications with Bun's bundler
Standalone HTML: Bundle a single-page app into a single self-contained .html file with no external dependencies
CSS: Bun's bundler has built-in support for CSS with modern features
Loaders: Built-in loaders for the Bun bundler and runtime
Single-file executable: Generate standalone executables from TypeScript or JavaScript files with Bun
Plugins: Universal plugin API for extending Bun's runtime and bundler
Macros: Run JavaScript functions at bundle-time with Bun macros
Bytecode Caching: Speed up JavaScript execution with bytecode caching in Bun's bundler
Minifier: Reduce bundle sizes with Bun's JavaScript and TypeScript minifier
esbuild: Migration guide from esbuild to Bun's bundler
Test runner: Bun's fast, built-in, Jest-compatible test runner with TypeScript support, lifecycle hooks, mocking, and watch mode
Writing tests: Write tests with Bun's Jest-compatible API, including async tests, timeouts, and test modifiers
Test configuration: Configure bun test behavior with bunfig.toml and command-line options
Runtime behavior: Learn about Bun test's runtime integration, environment variables, timeouts, and error handling
Finding tests: Learn how Bun's test runner discovers and filters test files in your project
Parallel & isolated test runs: Run test files across CPU cores with --parallel, isolate files from each other with --isolate, run tests within a file concurrently, and split suites across CI machines with --shard and --timings
Lifecycle hooks: Learn how to use beforeAll, beforeEach, afterEach, and afterAll lifecycle hooks in Bun tests
Mocks: Learn how to create and use mock functions, spies, and module mocks in Bun tests
Snapshots: Learn how to use snapshot testing in Bun to save and compare output between test runs
Dates and times: Learn how to manipulate time and dates in your Bun tests using setSystemTime and Jest compatibility functions
DOM testing: Learn how to test DOM elements and components using Bun with happy-dom and React Testing Library
Code coverage: Use Bun's built-in code coverage reporting to track test coverage and find untested code
Test Reporters
Guides: Code samples and walkthroughs for common tasks with Bun
Deploy a Bun application on Vercel
Deploy a Bun application on Railway: Deploy a Bun application to Railway from the CLI or dashboard, with optional PostgreSQL setup and automatic SSL
Deploy a Bun application on Render
Deploy a Bun application on AWS Lambda
Deploy a Bun application on DigitalOcean
Deploy a Bun application on Google Cloud Run
Install TypeScript declarations for Bun
Re-map import paths
Debugging Bun with the VS Code extension
Debugging Bun with the web debugger
Inspect memory usage using V8 heap snapshots
Build-time constants with --define
Define and replace static globals & constants
Install and run Bun in GitHub Actions
Codesign a single-file JavaScript executable on macOS: Fix the "can't be opened because it is from an unidentified developer" Gatekeeper warning when running your JavaScript executable.
Upgrade Bun to the latest version
Detect when code is executed with Bun
Get the current Bun version
Hash a password
Generate a UUID
Encode and decode base64 data
Compress and decompress data with gzip
Compress and decompress data with DEFLATE
Escape an HTML string
Check if two objects are deeply equal
Sleep for a fixed number of milliseconds
Convert a file URL to an absolute path
Convert an absolute path to a file URL
Get the path to an executable bin file
Get the directory of the current file
Get the file name of the current file
Get the absolute path of the current file
Check if the current file is the entrypoint
Get the absolute path to the current entrypoint
Build an app with Astro and Bun
Create a Discord bot
Containerize a Bun application with Docker
Use Drizzle ORM with Bun
Use Gel with Bun
Build an HTTP server using Elysia and Bun
Build an HTTP server using Express and Bun
Build an HTTP server using Hono and Bun
Read and write data to MongoDB using Mongoose and Bun
Use Neon Postgres through Drizzle ORM
Use Neon's Serverless Postgres with Bun
Build an app with Next.js and Bun
Build an app with Nuxt and Bun
Run Bun as a daemon with PM2
Use Prisma with Bun
Use Prisma Postgres with Bun
Build an app with Qwik and Bun
Build a React app with Bun
Build an app with Remix and Bun
Use TanStack Start with Bun
Add Sentry to a Bun app
Build an app with SolidStart and Bun
Server-side render (SSR) a React component
Build an app with SvelteKit and Bun
Run Bun as a daemon with systemd
Build a frontend using Vite and Bun
Bun Redis with Upstash
Common HTTP server usage
Write a simple HTTP server
Send an HTTP request using fetch
Hot reload an HTTP server
Start a cluster of HTTP servers: Run multiple HTTP servers concurrently with the "reusePort" option to share the same port across multiple processes
Configure TLS on an HTTP server
Proxy HTTP requests using fetch()
Stream a file as an HTTP Response
Upload files via HTTP using FormData
fetch with unix domain sockets in Bun
Streaming HTTP Server with Async Iterators
Server-Sent Events (SSE) with Bun
Streaming HTTP Server with Node.js Streams
Build a simple WebSocket server
Build a publish-subscribe WebSocket server
Set per-socket contextual data on a WebSocket
Enable compression for WebSocket messages
Spawn a child process
Read stdout from a child process
Read stderr from a child process
Parse command-line arguments
Read from stdin
Spawn a child process and communicate using IPC
Listen for CTRL+C
Listen to OS signals
Get the process uptime in nanoseconds
Run a Shell Command
Set a time zone in Bun
Set environment variables
Read environment variables
Add a dependency
Add a development dependency
Add an optional dependency
Add a peer dependency
Add a Git dependency
Add a tarball dependency
Install a package under a different name
Configuring a monorepo using workspaces
Override the default npm registry for bun install
Configure a private registry for an organization scope with bun install
Using bun install with an Azure Artifacts npm registry
Using bun install with Artifactory
Add a trusted dependency
Generate a yarn-compatible lockfile
Migrate from npm install to bun install
Configure git to diff Bun's lockb lockfile
Install dependencies with Bun in GitHub Actions
Run your tests with the Bun test runner
Run tests in watch mode with Bun
Migrate from Jest to Bun's test runner
Mock functions in
bun testSpy on methods in
bun testSet the system time in Bun's test runner
Use snapshot testing in
bun testUpdate snapshots in
bun testGenerate code coverage reports with the Bun test runner
Set a code coverage threshold with the Bun test runner
Selectively run tests concurrently with glob patterns: Set a glob pattern to decide which tests from which files run in parallel
Skip tests with the Bun test runner
Mark a test as a "todo" with the Bun test runner
Set a per-test timeout with the Bun test runner
Bail early with the Bun test runner
Re-run tests multiple times with the Bun test runner
Using Testing Library with Bun
Write browser DOM tests with Bun and happy-dom
import, require, and test Svelte components with bun test
Import a JSON file
Import a TOML file
Import a YAML file
Import a JSON5 file
Import an XML file
Import a HTML file as text
Read a file as a string
Read a file to a Buffer
Read a file to a Uint8Array
Read a file to an ArrayBuffer
Read a JSON file
Get the MIME type of a file
Check if a file exists
Watch a directory for changes
Read a file as a ReadableStream
Write a string to a file
Write a Blob to a file
Write a Response to a file
Append content to a file
Write a file incrementally
Write a ReadableStream to a file
Write to stdout
Write a file to stdout
Copy a file to another location
Delete a file
Delete files
Delete directories
Extract links from a webpage using HTMLRewriter
Extract social share images and Open Graph tags
Convert an ArrayBuffer to a string
Convert an ArrayBuffer to a Buffer
Convert an ArrayBuffer to a Blob
Convert an ArrayBuffer to an array of numbers
Convert an ArrayBuffer to a Uint8Array
Convert a Buffer to a string
Convert a Buffer to an ArrayBuffer
Convert a Buffer to a blob
Convert a Buffer to a Uint8Array
Convert a Buffer to a ReadableStream
Convert a Blob to a string
Convert a Blob to an ArrayBuffer
Convert a Blob to a Uint8Array
Convert a Blob to a DataView
Convert a Blob to a ReadableStream
Convert a Uint8Array to a string
Convert a Uint8Array to an ArrayBuffer
Convert a Uint8Array to a Buffer
Convert a Uint8Array to a Blob
Convert a Uint8Array to a DataView
Convert a Uint8Array to a ReadableStream
Convert a DataView to a string
Convert a ReadableStream to a string
Convert a ReadableStream to JSON
Convert a ReadableStream to a Blob
Convert a ReadableStream to a Buffer
Convert a ReadableStream to an ArrayBuffer
Convert a ReadableStream to a Uint8Array
Convert a ReadableStream to an array of chunks
Convert a Node.js Readable to a string
Convert a Node.js Readable to JSON
Convert a Node.js Readable to a Blob
Convert a Node.js Readable to an Uint8Array
Convert a Node.js Readable to an ArrayBuffer
Feedback: Share feedback, bug reports, and feature requests
Additional Resources (Optional)
Optional
Reference
Blog
- URL: https://bun.com/blog
How to Use This Skill
Reference these resources when working with Bun.