@effect/platform-bun package provides Bun-specific implementations of Effect’s platform abstractions, enabling you to leverage Bun’s high-performance runtime for building fast server-side applications.
Installation
When to Use
Use@effect/platform-bun when:
- Building server-side applications with Bun
- You want maximum performance with Bun’s optimized runtime
- You need Bun-specific features and APIs
- Building high-throughput HTTP servers or WebSocket applications
- You want faster startup times and lower memory usage
Core Features
Runtime
TheBunRuntime module provides the entry point for running Effect programs in Bun:
- Automatic error handling and logging
- Signal management (handles Ctrl+C gracefully)
- Exit code handling based on success/failure
- Optional custom teardown logic
- Optimized for Bun’s runtime characteristics
HTTP Server
Create high-performance HTTP servers with theBunHttpServer module:
- Built on Bun’s native HTTP server (faster than Node.js)
- Automatic HTTP/2 support
- Native WebSocket support
- Lower latency and higher throughput
HTTP Client
Make HTTP requests using theBunHttpClient module:
File System
Access the file system with theBunFileSystem module:
Child Processes
Spawn and manage child processes:WebSockets
Bun has first-class WebSocket support integrated into its HTTP server:Available Modules
| Module | Description |
|---|---|
BunRuntime | Run Effect programs as Bun applications |
BunHttpServer | Create high-performance HTTP servers |
BunHttpClient | Make HTTP requests (Bun-native) |
BunFileSystem | File system operations |
BunChildProcessSpawner | Spawn and manage child processes |
BunSocket | Socket client |
BunSocketServer | Socket server |
BunWorker | Worker thread management |
BunWorkerRunner | Worker runner for parallel processing |
BunPath | Path manipulation |
BunStdio | Standard input/output/error streams |
BunTerminal | Terminal interaction |
BunRedis | Redis client support |
BunClusterHttp | HTTP server clustering |
BunClusterSocket | Socket server clustering |
BunMultipart | Multipart form data handling |
BunStream | Bun stream integration |
BunSink | Stream sinks for Bun |
Platform Services
TheBunServices module provides a convenient layer that includes all common Bun services:
Performance Benefits
Bun offers several performance advantages:- Faster Startup: Bun starts significantly faster than Node.js
- Lower Memory: Reduced memory footprint for applications
- HTTP Speed: Native HTTP server is faster than Node.js http module
- File I/O: Optimized file system operations
- Built-in APIs: Many built-in APIs (SQLite, password hashing, etc.)
Migration from Node.js
Migrating from@effect/platform-node to @effect/platform-bun is straightforward:
Node prefix with Bun prefix.
Testing
The package includes test layers for HTTP servers:Dependencies
The package has minimal external dependencies and leverages Bun’s built-in capabilities:- @effect/platform-node-shared: Shared utilities with Node.js platform
- No heavy external dependencies (Bun provides most functionality natively)
Related Packages
- @effect/platform - Core platform abstractions
- @effect/platform-node - Node.js runtime implementations
- @effect/platform-browser - Browser implementations
