Skip to content

Repository files navigation

Kaelum

Kaelum

Fast, minimalist Node.js framework for web apps & REST APIs

npm version npm downloads CI License: MIT

📚 Documentation · 🐛 Report Bug · 💡 Request Feature


Why Kaelum?

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.


⚡ Quick Start

# 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 start

No global install needed — npx handles everything.

Available Templates

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 web and api map to js-web and js-api.


✨ Features

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

📦 Installation

npm install kaelum
// CommonJS
const kaelum = require("kaelum");
const app = kaelum();

// ESM
import kaelum from "kaelum";
const app = kaelum();

🧩 API Overview

app.setConfig(options)

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(path, handlers)

app.addRoute("/dashboard", {
  get: (req, res) => res.render("dashboard"),
  post: handleForm,
  "/settings": {
    get: showSettings,
    put: updateSettings,
  },
});

app.apiRoute(resource, handlers)

app.apiRoute("products", {
  get: listAll,
  post: create,
  "/:id": {
    get: getById,
    put: update,
    delete: remove,
    "/reviews": {
      get: getReviews,   // GET /products/:id/reviews
      post: addReview,
    },
  },
});

Other Helpers

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 close

CLI Commands

kaelum create              # interactive project scaffolding
kaelum --version           # show installed version
kaelum info                # show environment details
kaelum help                # show all commands

📁 Project Templates

JavaScript Web (js-web)

my-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

JavaScript API (js-api)

my-api/
├── controllers/       # Business logic
├── middlewares/        # Auth, validation
├── routes.js          # API routes
├── app.js             # Entry point
└── package.json

TypeScript Web (ts-web)

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

TypeScript API (ts-api)

my-api/
├── src/
│   ├── controllers/   # Business logic
│   ├── middlewares/    # Auth, validation
│   ├── routes.ts      # API routes
│   └── app.ts         # Entry point
├── tsconfig.json
└── package.json

🧪 Testing

npm test        # run all tests
npm run lint    # check code with ESLint
npm run format  # format code with Prettier

🤝 Contributing

We welcome contributions! Please read our Contributing Guide before submitting a PR.

See also: Code of Conduct · Security Policy


🌐 Ecosystem

Package Description
kaelum Core framework
kaelumjs/docs Documentation site
kaelumjs/.github Shared community standards

☕ Support

If Kaelum helps you, consider supporting its development:

Buy Me a Coffee at ko-fi.com


📝 License

MIT — see LICENSE.

About

Kaelum is a minimalist Node.js framework that abstracts Express.js.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

2 stars

Watchers

1 watching

Forks

Releases

Sponsor this project

Used by

Contributors

Languages