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()withreusePort) - node:dgram - UDP sockets (use native UDP in Bun)
- node:vm - Virtual machine
- node:repl - Interactive shell
- node:tty - Terminal control
Import Syntax
Use thenode: prefix to import Node.js modules:
node::
fs Module
Bun fully implements thenode:fs module:
http and https Modules
Create HTTP servers using Node.js APIs:Buffer
Bun implements the Node.jsBuffer class:
process
The globalprocess object is available:
__dirname and __filename
These globals are available in CommonJS modules:import.meta:
require()
Bun supportsrequire() for CommonJS modules:
require() in ESM files for better compatibility:
Module Resolution
Bun follows Node.js module resolution rules:- Resolve
node_modulesdirectories - Check
package.json"exports"field - Try file extensions:
.ts,.tsx,.js,.jsx,.json - Try
indexfiles
- Native TypeScript support (no need for ts-node)
- Automatic JSX transformation
- Import from
package.json"module"field
Package.json Compatibility
Bun reads standardpackage.json fields:
bun run:
Environment Variables
Access environment variables viaprocess.env:
.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:| Operation | Node.js API | Bun Native API |
|---|---|---|
| Read file | fs.readFileSync() | Bun.file().text() |
| Write file | fs.writeFileSync() | Bun.write() |
| HTTP server | http.createServer() | Bun.serve() |
| Spawn process | child_process.spawn() | Bun.spawn() |
| SQLite | better-sqlite3 | bun:sqlite |
| Hash | crypto.createHash() | Bun.hash() |
Migration Guide
To migrate a Node.js project to Bun:Known Differences
A few differences exist between Bun and Node.js:- Bun is faster: Startup time and runtime performance are significantly better
- Native TypeScript: No need for
ts-nodeor transpilation - Top-level await: Works everywhere, not just ES modules
- Different engine: JavaScriptCore instead of V8 (rare compatibility issues)
Check Compatibility
To check if a package works with Bun:- Check Bun compatibility tracker
- Try installing and running tests:
bun install && bun test - 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