princejs
v1.8.0
Published
An easy and fast backend framework that is among the top three — by a 13yo developer, for developers.
Maintainers
Readme
👑 PrinceJS
⚡ Ultra-clean, modern & minimal Bun web framework built by a 13 year old. Among the top three in performance.
🚀 Quick Start
bun create princejs my-app
cd my-app
bun devimport { prince } from "princejs";
import { cors, logger } from "princejs/middleware";
const app = prince();
app.use(cors());
app.use(logger());
app.get("/", () => ({ message: "Hello PrinceJS!" }));
app.get("/users/:id", (req) => ({ id: req.params.id }));
app.listen(3000);🧰 Features
import { cors, logger, rateLimit, serve } from "princejs/middleware";
import { validate } from "princejs/validation";
import { z } from "zod";
app
.use(cors())
.use(logger())
.use(rateLimit({ max: 100, window: 60 }))
.use(serve({ root: "./public" }))
.use(validate(z.object({
name: z.string(),
age: z.number()
})));✓ Middleware
- CORS
- Logger
- Rate Limiting
- Static Files
✓ Validation (Zod)
✓ File Uploads
✓ Response Builder
WebSocket Support
Auth & API Keys
Server-Sent Events
Sessions
Response Compression
Database (SQLite)
Performance With Oha (oha -c 100 -z 30s)
| Framework | Req/s | Total | |-----------|----------------|--------| | Elysia | 25,312 req/s | 759k | | Hono | 22,124 req/s | 664k | | PrinceJS | 21,748 req/s | 653k | | Express | 9,325 req/s | 280k |
Among the top three
🎯 Full Example
import { prince } from "princejs";
import { cors, logger, rateLimit, auth, apiKey, jwt, session, compress } from "princejs/middleware";
import { validate } from "princejs/validation";
import { cache, upload, sse } from "princejs/helpers";
import { cron } from "princejs/scheduler";
import { Html, Head, Body, H1, P, render } from "princejs/jsx"
import { db } from "princejs/db";
import { z } from "zod";
const app = prince(true);
app.use(cors());
app.use(logger());
app.use(rateLimit({ max: 100, window: 60 }));
app.use(validate(z.object({ name: z.string() })));
app.use(jwt(key));
app.use(session({ secret: "key" }));
app.use(compress());
const Page = () => (
Html({
children: [
Head({
children: [
"Test Page"
]
}),
Body({
children: [
H1({
children: "Hello World"
}),
P({
children: "This is a test"
})
]
})
]
})
);
const users = db.sqlite("./db.sqlite", "CREATE TABLE users...");
app.ws("/chat", {
open: (ws) => ws.send("Welcome!"),
message: (ws, msg) => ws.send(`Echo: ${msg}`)
});
app.get("/protected", auth(), (req) => ({ user: req.user }));
app.get("/api", apiKey({ keys: ["key_123"] }), handler);
app.get("/", () => ({ message: "Welcome to PrinceJS" }));
app.get("/users/:id", (req) => ({ id: req.params.id }));
app.get("/jsx", () => render(Page()));
app.get("/data", cache(60)(() => ({ time: Date.now() })));
app.post("/upload", upload(), (req) => ({ files: Object.keys(req.files || {}) }));
app.get("/events", sse(), (req) => {
setInterval(() => req.sseSend({ time: Date.now() }), 1000);
});
app.get("/count", (req) => ({ visits: req.session.visits++ || 1 }));
app.get("/users", () => users.query("SELECT * FROM users"));
cron("*/1 * * * *", () => console.log("PrinceJS heartbeat"));
app.listen(3000);📦 Installation
npm install princejs
# or
bun add princejs
# or
yarn add princejs📚 Documentation
Visit: princejs.vercel.app
🤝 Contributing
git clone https://github.com/MatthewTheCoder1218/princejs
cd princejs
bun install
bun test⭐ Star This Repo
If PrinceJS helped you, star the repo!
GitHub: https://github.com/MatthewTheCoder1218/princejs
🔗 Links
- npm: https://www.npmjs.com/package/princejs
- GitHub: https://github.com/MatthewTheCoder1218/princejs
- Twitter: https://twitter.com/Lil_Prince_1218
PrinceJS: Small in size. Giant in capability. 🚀
