UNPKG

tezx

Version:

TezX is a modern, ultra-lightweight, and high-performance JavaScript framework built specifically for Bun. It provides a minimal yet powerful API, seamless environment management, and a high-concurrency HTTP engine for building fast, scalable web applicat

201 lines (139 loc) โ€ข 3.5 kB
# โšก TezX โ€“ High-Performance JavaScript Framework for **Bun** **TezX** is a modern, ultra-fast, and lightweight JavaScript framework built specifically for **Bun**. With a clean API, powerful routing, WebSocket support, middleware stacking, and native static file serving โ€” TezX helps you build scalable applications with unmatched speed. [![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/tezxjs/TezX) --- ## ๐Ÿš€ Why TezX (Built for Bun)? * โšก **Blazing Fast** โ€” Fully optimized for Bunโ€™s event loop & native performance. * ๐Ÿงฉ **Minimal, Clean API** โ€” Developer-friendly and intuitive. * ๐Ÿ—‚ **Native Static Serving** โ€” No external dependencies needed. * ๐Ÿ”Œ **Powerful Middleware Engine** โ€” Compose any logic effortlessly. * ๐Ÿงญ **Advanced Routing** โ€” Dynamic, nested, and pattern-based. * ๐Ÿ” **Secure by Default** โ€” Built-in safe context handling. * ๐Ÿ“ก **WebSocket Support** โ€” Real-time apps made easy with `wsHandlers`. * โ™ป๏ธ **Multi-Process Ready** โ€” Via Bunโ€™s `reusePort`. --- ## ๐Ÿ“ฆ Installation ```bash bun add tezx # or npm install tezx ``` --- ## โšก Quick Start (Bun) ```ts import { TezX } from "tezx"; import { logger } from "tezx/middleware"; import { serveStatic } from "tezx/static"; import { wsHandlers } from "tezx/ws"; const app = new TezX(); // Middlewares app.use(logger()); // Static files app.static(serveStatic("/", "./static")); // Server const port = Number(process.env.PORT) || 3001; Bun.serve({ port, reusePort: true, fetch(req, server) { return app.serve(req, server); }, websocket: wsHandlers({ // Optional WebSocket config }), }); console.log(`๐Ÿš€ TezX server running at http://localhost:${port}`); ``` --- ## โ–ถ Run the Server ```bash bun run server.ts ``` --- ## ๐Ÿ”Œ Middleware Example ```ts app.use((ctx, next) => { console.log("โžก Request:", ctx.req.url); return next(); }); ``` --- ## ๐Ÿ—‚ Static File Serving ```ts import { serveStatic } from "tezx/static"; app.static(serveStatic("/assets", "./assets")); ``` Access via: ```bash http://localhost:3001/assets/your-file.ext ``` --- ## ๐Ÿงญ Routing ```ts app.post("/contact", async (ctx) => { const body = await ctx.json(); return ctx.json({ received: body }); }); ``` --- ## โš ๏ธ Error Handling ```ts app.onError((err, ctx) => { return ctx.status(500).json({ error: "Internal Server Error", message: err.message, }); }); ``` --- ## ๐Ÿงช Development Setup ### `dev` script for Bun **package.json** ```json { "scripts": { "dev": "bun run --hot --watch src/index.ts" } } ``` ### Example: `src/index.ts` ```ts import app from "./app"; Bun.serve({ port: 3001, reusePort: true, fetch(req, server) { return app.serve(req, server); }, }); ``` --- ## ๐Ÿค Contributing We welcome contributions! 1. Fork the repo 2. Create a new branch 3. Commit your changes 4. Open a pull request ๐Ÿ‘‰ GitHub: **[https://github.com/tezxjs](https://github.com/tezxjs)** --- ## ๐Ÿ’– Support TezX If TezX helps you, consider supporting: * โญ Star on GitHub * ๐Ÿ’ธ Sponsor on GitHub: [https://github.com/sponsors/srakib17](https://github.com/sponsors/srakib17) Your support helps improve the framework. --- ## ๐Ÿ™Œ Sponsor <a href="http://papernxt.com" target="_blank"> <img src="https://papernxt.com/favicon.ico" width="48" hight="48" alt="papernxt.com" title="papernxt.com" /> </a> --- ## ๐Ÿ“œ License Licensed under the **MIT License**. ---