|
Without Kaelum (raw Express) const express = require("express");
const cors = require("cors");
const helmet = require("helmet");
const morgan = require("morgan");
const path = require("path");
const app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cors());
app.use(helmet());
app.use(morgan("dev"));
app.use(express.static(path.join(__dirname, "public")));
app.set("view engine", "ejs");
app.get("/users", listUsers);
app.post("/users", createUser);
app.get("/users/:id", getUser);
app.listen(3000); |
With Kaelum ✨ const kaelum = require("kaelum");
const app = kaelum();
app.setConfig({
cors: true,
helmet: true,
logs: "dev",
port: 3000,
});
app.apiRoute("users", {
get: listUsers,
post: createUser,
"/:id": { get: getUser },
});
app.start(); |
Less boilerplate. Same Express power. Better DX.
# Scaffold a new project (interactive — picks language + template)
npx kaelum create my-app
# Or non-interactive with a specific template
npx kaelum create my-app --template js-web
npx kaelum create my-api --template js-api
npx kaelum create my-app --template ts-web
npx kaelum create my-api --template ts-api
# Run it
cd my-app && npm install && npm startNo global install needed —
npxhandles everything.
| Template | Language | Description |
|---|---|---|
js-web |
JavaScript | MVC with views & static files |
js-api |
JavaScript | REST API ready |
ts-web |
TypeScript | MVC with views & static files (tsx + tsc) |
ts-api |
TypeScript | REST API ready (tsx + tsc) |
Legacy aliases
webandapimap tojs-webandjs-api.
| Feature | Description |
|---|---|
| 🚀 Zero-Config Start | JSON parsing, static files, EJS views — all pre-configured |
| 🌳 Tree Routing | Recursive nested routes with addRoute and apiRoute |
| 🔒 Security Built-in | One-toggle CORS, Helmet, and XSS protection |
| 🛠️ CLI Scaffolding | npx kaelum create with JS and TS templates (web + API) |
| 📦 Dual Module | Works with both require() and import |
| 🏥 Health Checks | Built-in /health endpoint with readiness probes |
| ⚡ Middleware Manager | Track, add, and remove middleware programmatically |
| 🔄 Redirects | Declarative redirect maps with single, array, or object syntax |
| 🛡️ Error Handler | Standardized JSON/HTML error responses with hooks |
| ⏱️ Rate Limiting | Built-in zero-dependency in-memory rate limiter |
| 🧩 Plugin System | Register and manage plugins with dedup guard |
| 🔌 Graceful Shutdown | Signal handling, connection draining, and cleanup hooks |
npm install kaelum// CommonJS
const kaelum = require("kaelum");
const app = kaelum();
// ESM
import kaelum from "kaelum";
const app = kaelum();app.setConfig({
cors: true, // enable CORS
helmet: true, // HTTP security headers
static: "public", // serve static files
logs: "dev", // morgan request logging
bodyParser: true, // JSON + urlencoded (default: on)
port: 3000, // preferred port
views: { engine: "ejs", path: "./views" },
rateLimit: true, // enable rate limiting (default: 100 req/15 min)
gracefulShutdown: { timeout: 10000 }, // signal handling + cleanup
});app.addRoute("/dashboard", {
get: (req, res) => res.render("dashboard"),
post: handleForm,
"/settings": {
get: showSettings,
put: updateSettings,
},
});app.apiRoute("products", {
get: listAll,
post: create,
"/:id": {
get: getById,
put: update,
delete: remove,
"/reviews": {
get: getReviews, // GET /products/:id/reviews
post: addReview,
},
},
});app.start(3000); // start server
app.setMiddleware("/admin", authMiddleware); // scoped middleware
app.redirect("/old", "/new", 301); // redirects
app.healthCheck("/health"); // health endpoint
app.useErrorHandler({ exposeStack: false }); // error handling
app.plugin(myPlugin, { key: "value" }); // register plugin
app.onShutdown(() => cleanup()); // shutdown hook
app.close(); // graceful closekaelum create # interactive project scaffolding
kaelum --version # show installed version
kaelum info # show environment details
kaelum help # show all commandsmy-web-app/
├── public/ # Static assets
├── views/ # HTML templates
├── controllers/ # Route logic (MVC)
├── middlewares/ # Custom middleware
├── routes.js # Route definitions
├── app.js # Entry point
└── package.json
my-api/
├── controllers/ # Business logic
├── middlewares/ # Auth, validation
├── routes.js # API routes
├── app.js # Entry point
└── package.json
my-web-app/
├── public/ # Static assets
├── views/ # HTML templates
├── src/
│ ├── controllers/ # Route logic (MVC)
│ ├── middlewares/ # Custom middleware
│ ├── routes.ts # Route definitions
│ └── app.ts # Entry point
├── tsconfig.json
└── package.json
my-api/
├── src/
│ ├── controllers/ # Business logic
│ ├── middlewares/ # Auth, validation
│ ├── routes.ts # API routes
│ └── app.ts # Entry point
├── tsconfig.json
└── package.json
npm test # run all tests
npm run lint # check code with ESLint
npm run format # format code with PrettierWe welcome contributions! Please read our Contributing Guide before submitting a PR.
See also: Code of Conduct · Security Policy
| Package | Description |
|---|---|
| kaelum | Core framework |
| kaelumjs/docs | Documentation site |
| kaelumjs/.github | Shared community standards |
If Kaelum helps you, consider supporting its development:
MIT — see LICENSE.