Integration Guide
Leverage TezX on the ultra-fast Bun runtime to build modern, scalable APIs with WebSocket support.
Prerequisites
Make sure you have:
Install TezX via Bun:
bun add tezxRecommended Project Structure
project/
├── src/
│ └── app.ts # TezX app instance & routes
├── server.ts # Bun HTTP server entry point
├── .env # Environment variablesServer Setup (with WebSocket Support)
server.ts
import { wsHandlers } from "tezx/ws";
import { app } from "./src/app"; // TezX app instance
Bun.serve({
port: Number(process.env.PORT) || 3001,
reusePort: true, // Enables multi-process clustering
fetch(req, server) {
return app.serve(req, server); // Handle requests via TezX
},
websocket: wsHandlers({
// Optional WebSocket configure
})
});
console.log(`🚀 Server running at http://localhost:${process.env.PORT}`);Running the Server
Start with live-reload during development:
bun run --watch server.tsOr start normally:
bun run server.tsKey Concepts & Features
| Feature | Description |
|---|---|
Bun.serve() | Launches the HTTP server (similar to Node.js createServer) |
reusePort: true | Enables multi-process (cluster) support for improved scalability |
fetch(req, server) | Entry point for handling HTTP requests via TezX's app.serve() |
websocket | Manages WS lifecycle: open, message, close events |
ws.data | Attach custom session-specific data per WebSocket connection |
Pro Tips
- Clustering:
reusePort: trueallows Bun to spawn multiple processes for high-concurrency workloads. - WebSockets: Use
wsHandlers()to easily manage real-time connections and events. - Environment management: Always define
PORTand other sensitive values in.env. - Middleware-ready: TezX middlewares work seamlessly in Bun for logging, security, and more.
Create TezX
Easily scaffold a new TezX project optimized for Bun runtime. Whether you're building a backend with WebSocket support or a TypeScript-powered server, create-tezx sets up a Bun-ready project instantly — with optional npm support for installation.
Initialization
TezX is a high-performance, middleware-first server framework designed exclusively for the Bun runtime.