Skip to main content
Bun aims to be a drop-in replacement for Node.js. Most Node.js applications work with Bun with little to no changes. Bun implements the most commonly used Node.js built-in modules and APIs.

Built-in Module Support

Bun implements the following Node.js built-in modules:

Fully Supported

These modules are fully or nearly fully implemented:

node:fs

File system operations (sync and async)

node:path

File path manipulation

node:buffer

Binary data handling

node:stream

Streaming data

node:crypto

Cryptographic operations

node:http

HTTP client and server

node:https

HTTPS client and server

node:net

TCP networking

node:url

URL parsing and formatting

node:util

Utility functions

node:events

Event emitter

node:os

Operating system info

Partially Supported

These modules have most features implemented:
  • node:child_process - Spawn processes (use Bun.spawn() for better performance)
  • node:dns - DNS lookups
  • node:zlib - Compression (use Bun.gzipSync() for better performance)
  • node:readline - Command-line input
  • node:timers - setTimeout, setInterval
  • node:assert - Testing assertions
  • node:querystring - Query string parsing
  • node:worker_threads - Multi-threading
  • node:perf_hooks - Performance monitoring

Not Yet Implemented

These modules are planned but not yet available:
  • node:cluster - Load balancing (use Bun.serve() with reusePort)
  • node:dgram - UDP sockets (use native UDP in Bun)
  • node:vm - Virtual machine
  • node:repl - Interactive shell
  • node:tty - Terminal control

Import Syntax

Use the node: prefix to import Node.js modules:
Bun also supports the legacy syntax without node::
Both syntaxes work identically in Bun.

fs Module

Bun fully implements the node:fs module:
For better performance, use Bun.file() and Bun.write() instead of fs methods.

http and https Modules

Create HTTP servers using Node.js APIs:
For better performance, use Bun.serve() instead of the http module.

Buffer

Bun implements the Node.js Buffer class:

process

The global process object is available:

__dirname and __filename

These globals are available in CommonJS modules:
In ESM, use import.meta:

require()

Bun supports require() for CommonJS modules:
You can also use require() in ESM files for better compatibility:

Module Resolution

Bun follows Node.js module resolution rules:
  1. Resolve node_modules directories
  2. Check package.json "exports" field
  3. Try file extensions: .ts, .tsx, .js, .jsx, .json
  4. Try index files
Additional Bun features:
  • Native TypeScript support (no need for ts-node)
  • Automatic JSX transformation
  • Import from package.json "module" field

Package.json Compatibility

Bun reads standard package.json fields:
Run scripts with bun run:

Environment Variables

Access environment variables via process.env:
Bun automatically loads .env files. See Environment Variables.

npm Package Compatibility

Bun is compatible with most npm packages:
  • ✅ Pure JavaScript packages work without changes
  • ✅ Packages with native modules (Node-API/N-API) are supported
  • ✅ TypeScript packages work natively
  • ⚠️ Packages with node-gyp builds may need recompilation

Performance Comparison

While Bun maintains Node.js compatibility, Bun’s native APIs are often faster:
Use Bun’s native APIs for better performance, but Node.js APIs for maximum compatibility.

Migration Guide

To migrate a Node.js project to Bun:
1

Install Bun

2

Install dependencies

This reads your package.json and installs dependencies.
3

Update scripts

Replace node with bun in your scripts:
package.json
4

Test your application

Most apps work without changes!
5

Optional: Use Bun APIs

For better performance, replace Node.js APIs with Bun equivalents:
server.ts

Known Differences

A few differences exist between Bun and Node.js:
  1. Bun is faster: Startup time and runtime performance are significantly better
  2. Native TypeScript: No need for ts-node or transpilation
  3. Top-level await: Works everywhere, not just ES modules
  4. Different engine: JavaScriptCore instead of V8 (rare compatibility issues)

Check Compatibility

To check if a package works with Bun:
  1. Check Bun compatibility tracker
  2. Try installing and running tests: bun install && bun test
  3. Report issues at github.com/oven-sh/bun

Next Steps

Bun APIs

Learn about Bun-specific APIs

Package Manager

Use Bun’s fast package manager

Web APIs

Web standard APIs in Bun

Quickstart

Build your first Bun app