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
Markdown
# โก 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.
[](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**.