route-on
A lightweight, pragmatic routing and middleware framework with simple responses, static files, and body parsing.
32 downloads
v1.0.0
Updated 27 days ago
License: MIT
README
Routeon
A lightweight, pragmatic routing and middleware framework with simple responses, static files, and body parsing. Built for projects that use bnlang.
📦 Install
bpm install route-on
Use it in your app:
ধ্রুবক routeon = require("route-on");
🚀 Quick start (basic)
"use strict";
ধ্রুবক routeon = require("route-on");
ধ্রুবক app = routeon();
// Parsers (প্রতি JSON and urlencoded forms)
app.use(routeon.bodyParser.json());
app.use(routeon.bodyParser.urlencoded());
// Static files (optional)
app.use(routeon.serveStatic("public"));
// Routes
app.get("/", (req, res) => res.send("Hello from Routeon"));
app.get("/health", (req, res) => res.json({ ok: true }));
app.post("/echo", (req, res) => res.status(201).json({ ok: true, body: req.body || {} }));
// Global error handler
app.use((err, _req, res, _next) => {
ধ্রুবক status = err.status || 500;
res.status(status).json({ ok: false, error: err.message });
});
// 404 (last non-error middleware)
app.use(routeon.notFound((req, res, next) => {
res.status(404).json({ ok: false, error: 'Not Found' });
}));
// or
app.use(routeon.notFound());
app.listen(3000, () => লিখুন("listening on :3000"));
🧭 Middleware (basic)
A simple middleware ফাংশন that annotates the request:
ফাংশন hello(req, _res, next) {
req.hello = "world";
next();
}
Use it per route in either form:
// single middleware
app.get("/single", hello, (req, res) => {
res.json({ hello: req.hello });
});
// array form (app [middleware])
app.get("/array", [hello], (req, res) => {
res.json({ hello: req.hello });
});
Or apply globally:
app.use(hello);
License
RouteOn is licensed under the MIT.
Version History
v1.0.0
Latest
27 days ago