Skip to main content
Bun home page
English
Search...
⌘K
Install Bun
Search...
Navigation
Overview
Guides
Runtime
Package Manager
Bundler
Test Runner
Guides
Blog
Feedback
Overview
Guides
Deployment
Deploy on Vercel
Deploy on Railway
Deploy on Render
Deploy on AWS Lambda
Deploy on DigitalOcean
Deploy on Google Cloud Run
Runtime & Debugging
TypeScript types
Re-map import paths
VS Code debugger
Web debugger
Heap snapshots
Build-time constants
Define constants
GitHub Actions
Codesign on macOS
Utilities
Upgrade Bun
Detect Bun
Get Bun version
Hash password
Generate UUID
Base64 encoding
Gzip compression
DEFLATE compression
Escape HTML
Deep equality
Sleep
File URL to path
Path to file URL
Find executable path
import.meta.dir
import.meta.file
import.meta.path
Check entrypoint
Get entrypoint path
Ecosystem & Frameworks
Astro with Bun
Discord.js with Bun
Docker with Bun
Drizzle with Bun
Gel with Bun
Elysia with Bun
Express with Bun
Hono with Bun
Mongoose with Bun
Neon Drizzle with Bun
Neon Serverless Postgres with Bun
Next.js with Bun
Nuxt with Bun
PM2 with Bun
Prisma ORM with Bun
Prisma Postgres with Bun
Qwik with Bun
React with Bun
Remix with Bun
TanStack Start with Bun
Sentry with Bun
SolidStart with Bun
SSR React with Bun
StricJS with Bun
SvelteKit with Bun
systemd with Bun
Vite with Bun
Upstash with Bun
HTTP & Networking
HTTP Server with Bun
Simple HTTP Server with Bun
Fetch with Bun
Hot reload an HTTP server
Start a cluster of HTTP servers
Configure TLS
Proxy HTTP requests using fetch()
Stream file response
Upload files via HTTP using FormData
Fetch with unix domain sockets
Stream with iterators
Stream with Node.js
WebSocket
Simple server
Pub-sub server
Contextual data
Enable compression
Processes & System
Spawn child process
Read stdout
Read stderr
Parse command-line arguments
Read from stdin
Spawn a child process and communicate using IPC
Listen for CTRL+C
OS signals
Process uptime
Run shell command
Set time zone
Set env variables
Read env variables
Package Manager
Add a dependency
Add a dev dependency
Add an optional dependency
Add a peer dependency
Add a Git dependency
Add a tarball dependency
Install with alias
Workspaces with Bun
Override the default npm registry
Configure a scoped registry
Azure Artifacts with Bun
JFrog Artifactory with Bun
Add a trusted dependency
Generate a yarn-compatible lockfile
Migrate from npm to bun
Configure git to diff Bun's lockfile
Install Bun in GitHub Actions
Test Runner
Run tests
Watch mode
Migrate from Jest
Mock functions
Spy on methods
Mock system time
Snapshot testing
Update snapshots
Coverage reports
Coverage threshold
Concurrent test glob
Skip tests
Todo tests
Test timeout
Bail early
Re-run tests
Testing Library
DOM tests
Test Svelte
Runtime & Debugging
VS Code debugger
Web debugger
Heap snapshots
Build-time constants
Define constants
GitHub Actions
Codesign on macOS
Module System
Import JSON
Import TOML
Import YAML
Import HTML
import.meta.dir
import.meta.file
import.meta.path
Check entrypoint
Get entrypoint path
File System
Read as string
Read to Buffer
Read to Uint8Array
Read to ArrayBuffer
Read JSON file
Get MIME type
Check file exists
Watch directory
Read as stream
Write string to file
Write Blob
Write Response
Append to file
Incremental write
Write stream
Write to stdout
Write file to stdout
Copy file
Delete file
Delete files
Delete directories
Utilities
Hash password
Generate UUID
Base64 encoding
Gzip compression
DEFLATE compression
Escape HTML
Deep equality
Sleep
File URL to path
Path to file URL
Find executable path
HTML Processing
Extract links using HTMLRewriter
OpenGraph tags
Binary Data
ArrayBuffer to string
ArrayBuffer to Buffer
ArrayBuffer to Blob
ArrayBuffer to Array
ArrayBuffer to Uint8Array
Buffer to string
Buffer to ArrayBuffer
Buffer to Blob
Buffer to Uint8Array
Buffer to ReadableStream
Blob to string
Blob to ArrayBuffer
Blob to Uint8Array
Blob to DataView
Blob to ReadableStream
Uint8Array to string
Uint8Array to ArrayBuffer
Uint8Array to Buffer
Uint8Array to Blob
Uint8Array to DataView
Uint8Array to ReadableStream
DataView to string
Streams
Stream to string
Stream to JSON
Stream to Blob
Stream to Buffer
Stream to ArrayBuffer
Stream to Uint8Array
Stream to array
Readable to string
Readable to JSON
Readable to Blob
Readable to Uint8Array
Readable to ArrayBuffer
Overview
Guides
Copy page
A collection of code samples and walkthroughs for performing common tasks with Bun.
Copy page
Featured
Use Tanstack Start with Bun
View guide
Use Next.js with Bun
View guide
Build a frontend using Vite and Bun
View guide
Install TypeScript declarations for Bun
View guide
Write a simple HTTP server
View guide
Build a simple WebSocket server
View guide
All Guides
Deployment
Deploy Bun on Vercel
Deploy Bun on Railway
Deploy Bun on Render
Binary data
Convert an ArrayBuffer to an array of numbers
Convert an ArrayBuffer to a Blob
Convert an ArrayBuffer to a Buffer
Convert an ArrayBuffer to a string
Convert an ArrayBuffer to a Uint8Array
Convert a Blob to an ArrayBuffer
Convert a Blob to a DataView
Convert a Blob to a ReadableStream
Convert a Blob to a string
Convert a Blob to a Uint8Array
Convert a Buffer to an ArrayBuffer
Convert a Buffer to a blob
Convert a Buffer to a ReadableStream
Convert a Buffer to a string
Convert a Buffer to a Uint8Array
Convert a DataView to a string
Convert a Uint8Array to an ArrayBuffer
Convert a Uint8Array to a Blob
Convert a Uint8Array to a Buffer
Convert a Uint8Array to a DataView
Convert a Uint8Array to a ReadableStream
Convert a Uint8Array to a string
Ecosystem
Use Gel with Bun
Use Prisma ORM with Bun
Use Prisma Postgres with Bun
Create a Discord bot
Add Sentry to a Bun app
Use Drizzle ORM with Bun
Build a React app with Bun
Run Bun as a daemon with PM2
Build an app with Nuxt and Bun
Build an app with Qwik and Bun
Build an app with Astro and Bun
Build an app with Remix and Bun
Use TanStack Start with Bun
Run Bun as a daemon with systemd
Build an app with Next.js and Bun
Build an app with SvelteKit and Bun
Build a frontend using Vite and Bun
Build an app with SolidStart and Bun
Use Neon Postgres through Drizzle ORM
Build an HTTP server using Hono and Bun
Use Neon's Serverless Postgres with Bun
Build an HTTP server using Elysia and Bun
Containerize a Bun application with Docker
Build an HTTP server using Express and Bun
Server-side render (SSR) a React component
Build an HTTP server using StricJS and Bun
Read and write data to MongoDB using Mongoose and Bun
HTMLRewriter
Extract links from a webpage using HTMLRewriter
Extract social share images and Open Graph tags
HTTP
Common HTTP server usage
Hot reload an HTTP server
Write a simple HTTP server
Start a cluster of HTTP servers
Configure TLS on an HTTP server
Send an HTTP request using fetch
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
Streaming HTTP Server with Node.js Streams
Package manager
Add a dependency
Add a Git dependency
Add a peer dependency
Add a tarball dependency
Add a trusted dependency
Add an optional dependency
Add a development dependency
Using bun install with Artifactory
Generate a yarn-compatible lockfile
Migrate from npm install to bun install
Configuring a monorepo using workspaces
Install a package under a different name
Configure git to diff Bun's lockb lockfile
Install dependencies with Bun in GitHub Actions
Override the default npm registry for bun install
Using bun install with an Azure Artifacts npm registry
Configure a private registry for an organization scope with bun install
Processes
Read from stdin
Listen for CTRL+C
Listen to OS signals
Spawn a child process
Parse command-line arguments
Read stderr from a child process
Read stdout from a child process
Get the process uptime in nanoseconds
Spawn a child process and communicate using IPC
Reading files
Read a JSON file
Check if a file exists
Read a file to a Buffer
Read a file as a string
Get the MIME type of a file
Read a file to a Uint8Array
Read a file to an ArrayBuffer
Watch a directory for changes
Read a file as a ReadableStream
Runtime
Delete files
Delete directories
Import a JSON file
Import a TOML file
Import a YAML file
Run a Shell Command
Re-map import paths
Set a time zone in Bun
Set environment variables
Import a HTML file as text
Read environment variables
Build-time constants with --define
Debugging Bun with the web debugger
Install and run Bun in GitHub Actions
Install TypeScript declarations for Bun
Debugging Bun with the VS Code extension
Inspect memory usage using V8 heap snapshots
Define and replace static globals & constants
Codesign a single-file JavaScript executable on macOS
Streams
Convert a ReadableStream to JSON
Convert a Node.js Readable to JSON
Convert a ReadableStream to a Blob
Convert a Node.js Readable to a Blob
Convert a ReadableStream to a Buffer
Convert a ReadableStream to a string
Convert a Node.js Readable to a string
Convert a ReadableStream to a Uint8Array
Convert a ReadableStream to an ArrayBuffer
Convert a Node.js Readable to an Uint8Array
Convert a Node.js Readable to an ArrayBuffer
Convert a ReadableStream to an array of chunks
Test runner
Mock functions in bun test
Spy on methods in bun test
Using Testing Library with Bun
Update snapshots in bun test
Run tests in watch mode with Bun
Use snapshot testing in bun test
Bail early with the Bun test runner
Skip tests with the Bun test runner
Migrate from Jest to Bun's test runner
Run your tests with the Bun test runner
Set the system time in Bun's test runner
Write browser DOM tests with Bun and happy-dom
Set a per-test timeout with the Bun test runner
Mark a test as a "todo" with the Bun test runner
Re-run tests multiple times with the Bun test runner
Set a code coverage threshold with the Bun test runner
Selectively run tests concurrently with glob patterns
Generate code coverage reports with the Bun test runner
import, require, and test Svelte components with bun test
Utilities
Hash a password
Generate a UUID
Escape an HTML string
Get the current Bun version
Encode and decode base64 strings
Check if two objects are deeply equal
Detect when code is executed with Bun
Get the directory of the current file
Get the file name of the current file
Convert a file URL to an absolute path
Compress and decompress data with gzip
Convert an absolute path to a file URL
Get the path to an executable bin file
Sleep for a fixed number of milliseconds
Compress and decompress data with DEFLATE
Get the absolute path of the current file
Check if the current file is the entrypoint
Get the absolute path to the current entrypoint
WebSocket
Build a simple WebSocket server
Enable compression for WebSocket messages
Build a publish-subscribe WebSocket server
Set per-socket contextual data on a WebSocket
Writing files
Delete a file
Write to stdout
Write a Blob to a file
Write a file to stdout
Append content to a file
Write a string to a file
Write a file incrementally
Write a Response to a file
Copy a file to another location
Write a ReadableStream to a file
Deploy a Bun application on Vercel
Next
⌘I