Quick Start
Get a working API running in under 5 minutes.
1. Create the Project
Section titled “1. Create the Project”npx kaelum create my-api --template js-apicd my-apiThe CLI scaffolds a ready-to-run project:
my-api/├── controllers/│ └── usersController.js ← business logic├── middlewares/│ └── authMock.js ← example middleware├── routes.js ← route definitions├── app.js ← entry point├── .env ← environment variables└── package.json2. Understand the Entry Point
Section titled “2. Understand the Entry Point”Open app.js — this is the entire server:
const kaelum = require("kaelum");const routes = require("./routes");const app = kaelum();
app.setConfig({ cors: true, // cross-origin requests helmet: true, // security headers logs: "dev", // request logging port: 3000,});
routes(app);app.healthCheck();app.useErrorHandler();app.start();What’s happening:
kaelum()creates a pre-configured Express appsetConfig()activates CORS, Helmet, Morgan, and sets the portroutes(app)registers your API endpointshealthCheck()addsGET /healthfor monitoringuseErrorHandler()catches unhandled errors globallystart()launches the HTTP server with graceful shutdown
3. Start the Server
Section titled “3. Start the Server”npm startYou should see:
🛡️ CORS activated.🛡️ Helmet activated.📊 Request logging enabled (morgan: dev).🚀 Kaelum server running at http://localhost:30004. Test Your API
Section titled “4. Test Your API”# List userscurl http://localhost:3000/users
# Create a usercurl -X POST http://localhost:3000/users \ -H "Content-Type: application/json" \ -d '{"name": "Charlie", "email": "charlie@example.com"}'
# Get a usercurl http://localhost:3000/users/1
# Health checkcurl http://localhost:3000/health5. Add Your Own Route
Section titled “5. Add Your Own Route”Open routes.js and add a new resource:
module.exports = (app) => { // existing users routes...
// Add a new resource app.apiRoute("products", { get: (req, res) => res.json([{ id: 1, name: "Widget" }]), post: (req, res) => res.status(201).json(req.body), });};Restart the server and test:
curl http://localhost:3000/productsNext Steps
Section titled “Next Steps”- 📖 CLI Reference — all templates and options
- ⚙️ setConfig() — configuration options
- 🛣️ addRoute() — routing patterns
- 🔌 Plugin System — extend with plugins