Bun Node.js Compatibility
One of Bun's design goals is compatibility with the Node.js ecosystem. This chapter introduces Bun's Node.js compatibility and migration guide.
Compatibility Overview
Supported Node.js APIs
Bun supports most Node.js core modules:
Partially Supported APIs
Using Node.js APIs
Import Methods
File System
HTTP Server
Child Processes
Cryptography
Migrating from Node.js
Step 1: Install Bun
Step 2: Switch Package Manager
Step 3: Update package.json
Step 4: Check Compatibility
Common Migration Issues
Issue 1: Module Not Found
Issue 2: Native Modules
Issue 3: Node.js Specific APIs
Issue 4: __dirname and __filename
Bun vs Node.js API Comparison
File Operations
HTTP Server
Environment Variables
Running TypeScript
Using Bun Alternatives
Replacing Express
Replacing Jest
Replacing webpack/esbuild
Progressive Migration
Strategy 1: Partial Bun Usage
Strategy 2: Conditional Usage
Strategy 3: Abstraction Layer
Compatibility Check Tools
Check Package Compatibility
Test Run
Known Limitations
Incompletely Supported Features
- cluster module: Limited support
- vm module: Partial functionality
- Some Node.js internal APIs
- Specific native modules
Solutions
Summary
This chapter covered:
- ✅ Bun's compatibility with Node.js APIs
- ✅ How to use Node.js modules
- ✅ Steps to migrate from Node.js
- ✅ Common migration issues and solutions
- ✅ Bun alternatives
- ✅ Progressive migration strategies
Next Steps
Continue reading Learning Resources for more learning materials.