Home About Features Install Usage

CLI Commands

carabao create <name>

Scaffold a new MVC project. Generates the full directory structure, configuration files, and example code.

Flag Type Default Description
--pm string npm Package manager to use (npm, yarn, pnpm)

Examples:

# Default (npm)
npx carabao create my-app

# With yarn
npx carabao create my-app --pm yarn

# With pnpm
npx carabao create my-app --pm pnpm

Project Structure

The scaffolded project follows a clean MVC layout:

my-app/
├── index.ts # Entry point
├── esbuild.config.js # Build configuration
├── tsconfig.json # TypeScript config
├── .env # Environment variables
├── app/
│ ├── config/
│ │ └── routes.ts # Route definitions
│ ├── controllers/ # Request handlers
│ ├── middlewares/ # Express middlewares
│ ├── constants/ # App constants
│ └── database/ # Database setup / models
└── public/ # Static assets

API Reference

createApp(options)

Creates and configures an Express application instance.

Option Type Default Description
root string __dirname Project root directory
routes Route[] [] Array of route definitions
controllers object {} Controller map for auto-wiring
init object { port: 9000 } Server configuration

Application

The core application class with a familiar Express-like API.

Method Description
get()Register a GET route
post()Register a POST route
put()Register a PUT route
delete()Register a DELETE route
use()Mount middleware
serve()Start the HTTP server

Examples

Application setup

import "dotenv/config";
import path from "path";
import { createApp } from "carabao";
import routes from "./app/config/routes";
import controllers from "./app/controllers/controllers";

const root = path.basename(__dirname) === "dist"
  ? path.resolve(__dirname, "..")
  : __dirname;
const app = createApp({ root, routes, controllers });

(async () => {
  const { address, port } = await app.serve();
  console.log(`Server at http://${address}:${port}`);
})();

Route definition

import { controllers } from "../controllers/controllers";

export default [
  { method: "get", path: "/users", handler: controllers.getUsers },
  { method: "get", path: "/users/:id", handler: controllers.getUser },
  { method: "post", path: "/users", handler: controllers.createUser },
];

Controller

import { Request, Response } from "express";

export function getUsers(req: Request, res: Response) {
  res.json([{ id: 1, name: "Alice" }]);
}

export function getUser(req: Request, res: Response) {
  res.json({ id: req.params.id, name: "Alice" });
}

export function createUser(req: Request, res: Response) {
  res.status(201).json(req.body);
}

Using the Application class

// CommonJS
const { Application, createApp } = require("carabao");
const app = new Application({ init: { port: 9000 } });
app.get("/", (req, res) => res.send("Hello"));
app.serve();
// ESM / TypeScript
import { Application, createApp } from "carabao";
const app = new Application({ init: { port: 9000 } });
app.get("/", (req, res) => res.send("Hello"));
await app.serve();