Skip to main content

CLI

The Carno.js CLI provides essential tools for managing your application, including database migrations, seeders, and route inspection.

Installation

The CLI is distributed as a separate package. You can install it as a development dependency.

bun add -d @carno.js/cli

Using npm

npm install -D @carno.js/cli

Usage

Once installed, you can run the CLI using bunx or npx.

bunx carno --help

Common Commands

Routes

To list all registered routes in your application:

# Analyze carno.config.ts and list routes
bunx carno routes

# Or point to your entry file if config is not enough
bunx carno routes src/index.ts

For more details on routing, see the Controllers & Routing documentation.

Migrations

To manage database migrations:

# Generate a new migration based on entity changes
bunx carno migration:generate

# Apply pending migrations
bunx carno migration:run

For a comprehensive guide on migrations, refer to the Migrations documentation.

Seeders

Seeders let you insert or update data through executable classes.

# Generate a seeder (name is required)
bunx carno seeder:generate UserSeeder

# Run one specific seeder class
bunx carno seeder:run UserSeeder

# Run all seeders in registry order
bunx carno seeder:run --all

When the first seeder is generated, Carno creates a seeders.ts registry file in your seeder directory. Each new generated seeder is appended to the end of the exported seeders array. You can manually reorder this array, and that order is exactly what seeder:run --all will execute.

Generated seeder template:

import type { Orm } from "@carno.js/orm";

export default class UserSeeder {
async run(orm: Orm<any>) {
// Example:
// await orm.driverInstance.executeSql("INSERT INTO users (email) VALUES ('admin@example.com')");
}
}

You can also configure a custom seeder directory in carno.config.ts:

import { ConnectionSettings, BunPgDriver } from '@carno.js/orm';

const config: ConnectionSettings = {
driver: BunPgDriver,
migrationPath: './src/migrations',
seederPath: './src/seeders',
};

export default config;