CLI

AxilJS Project Commands

Reference for every axil project command in AxilJS 0.4.2: create, generate, migrate, run, test, build, install, deploy, doctor.

13 min readUpdated DocumentationEdit this page
On this page15

Every command below accepts --help / -h. Run them from the project root (the folder with package.json), except axil create. For axil capacity see Capacity; for axil decorator see Decorator Commands.

axil create

Terminal
❯axil create [name] [options]

Creates a new project in ./<name>, writes the files, runs npm install and prints numbered next steps.

OptionDescription
-t, --template <id>Start from a template: minimal, rest-api, realtime-chat, background-jobs, ai-assistant, saas-api, microservice, webhook-receiver, live-dashboard, high-scale-api
-y, --yesAccept defaults for every option not given as a flag (no prompts)
--db <driver>none (default), sqlite, postgres, mysql
--auth / --no-authJWT + RBAC auth (default: on)
--aiInclude the AI platform (default: off)
--wsInclude WebSocket support (default: off)
--queueInclude Queue and Scheduler (default: off)
--skip-installDo not run npm install
--forceAllow creating into an existing non-empty directory

Interactive flow

On a terminal, anything you did not pass is asked for in four steps:

  1. 1/4 Project name: only when no name was given. Letters, numbers, ., -, _; it cannot start with . or -.
  2. 2/4 Template picker: categories Start, APIs, Realtime, Background, AI, Production and Custom. ↑ ↓ move (and flow across categories at the ends), ← → or tab switch category, space / enter select, / searches every category, esc leaves the search or cancels.
  3. 3/4 Database and features: only for Custom. A database select, then one multi-select for Authentication, WebSocket, Queue and AI platform.
  4. 4/4 Confirm: a summary card (template, category, packages, port and location; or the custom stack), then Create project?.

Rules

  • Without a TTY or with --yes there are no prompts and a name is required.
  • --template cannot be combined with --db, --auth, --ai, --ws or --queue. Giving any of those flags without --template skips the picker and creates a Custom project.
  • An unknown template id fails with a suggestion, for example Unknown template "rest". Did you mean "rest-api"?.
  • Every new project gets @axiljs/cli, @axiljs/studio, @axiljs/testing, typescript and @types/node as devDependencies, so axil run can start Studio and npm test works immediately. Sibling @axiljs/* packages get the CLI's own version as range, for example ^0.4.2 (changed in 0.3.7; earlier CLIs wrote ^0.3.0).
  • If scaffolding or npm install fails, the CLI says where the partial project was left so you can remove it before retrying.
Terminal
❯axil create my-api
❯axil create my-api --yes
❯axil create my-api --db=sqlite --auth --ws --skip-install
❯axil create my-api -y --db postgres --no-auth --queue
❯axil create shop --template rest-api
❯axil create chat -t realtime-chat --skip-install

axil generate

Terminal
❯axil generate <module|controller|service|entity|migration> <name> [options]
❯axil g <kind> <name>

Generates files in the layout axil create uses:

KindFiles
modulesrc/modules/<name>/controllers/<name>.controller.ts, src/modules/<name>/services/<name>.service.ts, and src/migrations/<NNN>_create_<table>.ts when a database is configured
controllersrc/modules/<name>/controllers/<name>.controller.ts
servicesrc/modules/<name>/services/<name>.service.ts
entitysrc/modules/<name>/entities/<name>.entity.ts
migrationsrc/migrations/<NNN>_<name>.ts (the next free number)
OptionDescription
--forceOverwrite files that already exist (otherwise they are skipped with a warning)
--db <driver>Database driver for the templates (default: detected from package.json)
--authProtect the list route with authenticate() (default: detected from package.json)
Terminal
❯axil generate module products
❯axil g controller orders
❯axil g entity product
❯axil g migration add_price_to_products

Register a generated controller in src/main.ts: new ProductsController().register(app).

axil generate client (new in 0.4.0) writes a typed TypeScript API client from an OpenAPI document instead; see Generate Client.

axil migrate

Terminal
❯axil migrate [up|down|status|check] [options]

Runs the @axiljs/orm MigrationRunner. up (the default) applies pending migrations, down rolls back the last batch, status shows applied and pending ones, and check (or --check) analyzes migrations for unsafe statements without running them.

It loads .env from the project directory (variables already set in the environment win) and connects with:

VariableMeaning
DB_DRIVERsqlite, postgres or mysql (optional; inferred otherwise)
DATABASE_URLpostgres://… or mysql://… connection string
DATABASE_FILENAMESQLite file (DB_FILE is accepted as an alias)

Migrations default to src/migrations. Loading .ts migrations directly needs Node.js 22.18 or newer (type stripping); when Node cannot load .ts files and dist/migrations exists, dist/migrations is used. --dir points somewhere else.

Terminal
❯axil migrate
❯axil migrate status
❯axil migrate down
❯axil migrate up --dir=dist/migrations
OptionDescription
--dir <path>Migrations directory (default: src/migrations)
--checkCheck migrations for locking and breaking changes; runs nothing. Same as axil migrate check
--allWith --check: analyze every migration, not only pending ones
--jsonWith --check: print the report as JSON on stdout, with no other output
--safety <off|warn|block>With up: check pending migrations first. Default: package.json axil.migrationSafety, else off
--large-table <table>=<rows>Approximate row count; escalates lock findings on large tables. Repeatable; k, m and b suffixes are allowed

--all and --json are only accepted with --check, and --safety only with up.

Migration safety check

New in 0.4.0. axil migrate --check runs the migration safety analysis of @axiljs/orm over pending migrations: each migration's up() runs against a recording driver, so the SQL is captured, nothing is executed and no database file is created. Findings are printed per migration file with their severity, rule id, table, lock, explanation and the zero-downtime alternative, followed by a summary.

Terminal
❯axil migrate --check # pending migrations (same as `axil migrate check`)
❯axil migrate --check --all # every migration file
❯axil migrate check --all --json > migration-safety.json
❯axil migrate --check --large-table users=4200000 --large-table orders=18m
❯axil migrate up --safety=warn # print the findings, then migrate
❯axil migrate up --safety=block # refuse to migrate while an error finding remains
--safetyBehaviour of up
offNo check (the default without a project setting)
warnPrints the findings, then migrates
blockPrints the findings and runs no migration while any finding is an error

Pending without a database. "Pending" is determined from the _migrations table. When the database cannot be reached, the SQLite file does not exist yet, or DB_DRIVER is set without DATABASE_URL, every migration is treated as pending. --check --all does not connect at all. In CI, DB_DRIVER=postgres axil migrate --check therefore analyzes every migration with the PostgreSQL rules, without a database.

Large tables. --large-table values become the runner's tableSizes. Findings whose cost grows with the table are escalated one level on tables above 1,000,000 rows. Rows accept underscores and a k, m or b suffix: users=4_200_000, orders=18m, users=4.2m. Several entries may also be comma-separated.

Project defaults. up keeps the check off unless configured. A project can opt in, and record table sizes, in package.json; command-line flags take precedence:

JSON
JSON
1{
2  "axil": {
3    "migrationSafety": "warn",
4    "migrationTableSizes": { "users": 4200000, "orders": 18000000 }
5  }
6}

An invalid migrationSafety value is an error. Mark an intended statement with a -- axil:allow <rule> comment, as described in Acknowledge an intended change.

Output. For one pending migration that builds an index and changes a column type, checked with DB_DRIVER=postgres and no database:

Output
TXT
  ┌  axil migrate  Check migrations for locking and breaking changes
  │
  │    Driver        postgres
  │    Migrations    src/migrations
  │    Large tables  users (4,200,000 rows)
  │
  ◆  Migration safety
  ●  No database to compare against  every migration is treated as pending
  │
  ○  007_index_users_email  src/migrations/007_index_users_email.js  3 findings
  ■  error   create-index-non-concurrent  table users  ·  lock SHARE
  │    CREATE INDEX on existing table users takes a SHARE lock: INSERT, UPDATE and DELETE are blocked until the index is built. users has about 4,200,000 rows.
  │    Fix: Use CREATE INDEX CONCURRENTLY. It cannot run inside a transaction block, so export `transaction = false` from the migration. If it fails it leaves an INVALID index behind: drop it and retry.
  │    SQL: CREATE INDEX idx_users_email ON users (email)
  ■  error   alter-column-type  table users  ·  lock ACCESS EXCLUSIVE
  │    ...
  ▲  warning missing-lock-timeout  table users
  │    ...
  │
  │  1 migration checked  ·  2 errors, 1 warning, 0 info
  │
  ■  2 errors in 1 migration
  │  Fix the statements, or mark an intended one with "-- axil:allow <rule>".
  │
  └

With --large-table users=4.2m, the index build and the missing lock_timeout are escalated one level each (warning to error, info to warning).

JSON report. --json prints only the report, so it can be redirected. The same check without --large-table, shortened to one finding:

JSON
JSON
1{
2  "ok": false,
3  "driver": "postgres",
4  "scope": "pending",
5  "offline": true,
6  "counts": { "migrations": 1, "findings": 3, "error": 1, "warning": 1, "info": 1 },
7  "migrations": [
8    {
9      "name": "007_index_users_email",
10      "file": "src/migrations/007_index_users_email.js",
11      "statements": 2,
12      "findings": [
13        {
14          "rule": "alter-column-type",
15          "severity": "error",
16          "table": "users",
17          "lock": "ACCESS EXCLUSIVE",
18          "statement": "ALTER TABLE users ALTER COLUMN name TYPE integer",
19          "message": "Changing the type of users.name to integer rewrites users and its indexes under an ACCESS EXCLUSIVE lock: no reads or writes until it finishes.",
20          "fix": "Expand/contract: add a new column with the new type, write to both (or use a trigger), backfill in batches, switch reads, deploy, then drop the old column. Only varchar/numeric widenings and varchar → text are safe in place."
21        }
22      ]
23    }
24  ]
25}
FieldDescription
okfalse when any finding is an error
driversqlite, postgres or mysql
scopepending, or all with --all
offlinetrue when no database was used and every migration was treated as pending
countsMigrations analyzed, findings, and findings per severity
migrationsPer migration: name, project-relative file, number of captured statements, and findings (errors first) with rule, severity, table, lock, statement, message, fix

Exit codes.

CodeWhen
0--check found no error (warnings and info do not fail); up, down and status succeeded
1--check found at least one error finding
1up --safety=block refused to run
1Any other failure: no database configured, migrations directory not found, an invalid flag value, a failing migration

In CI:

YAML
YAML
1- run: npm ci
2- run: npx axil migrate --check
3  env:
4    DB_DRIVER: postgres

axil run

Terminal
❯axil run

The development server. It takes no options.

  1. Checks for package.json, tsconfig.json and src/.
  2. Compiles with tsc --incremental --noEmitOnError.
  3. Starts the first entry it finds: dist/main.js, dist/server.js, dist/index.js, or the same names under dist/src/.
  4. Starts Studio on the app port + 1. The app port is PORT from .env (default 3000).
  5. Watches src/ for .ts / .tsx changes, recompiles and restarts the app. Compile errors are printed and the running app is left alone until the next save.
Output
TXT
  12:04:31 ✔ Restarted in 320ms  src/app.ts · #1

If @axiljs/studio cannot be found (project node_modules first), axil run keeps going without it and prints:

Output
TXT
  → Studio skipped  @axiljs/studio not installed: npm install -D @axiljs/studio

Projects created with axil create 0.3.3 or later already include it. Ctrl+C stops Studio and the app (SIGTERM, then SIGKILL after 3 seconds).

axil test

Terminal
❯axil test [pattern]

Finds *.test.ts, *.spec.ts, *.test.js and *.spec.js under src/ and tests/, optionally filtered by a substring of the path. TypeScript tests inside rootDir are compiled first with tsc -p tsconfig.json and the compiled files are run, so ESM imports ending in .js resolve. Tests run on the project's own @axiljs/testing. The exit code is 1 when a test fails, a file fails to load, or compilation fails.

Terminal
❯axil test
❯axil test users

axil build

Terminal
❯axil build

Runs tsc --noEmit (type check), then tsc, and reports the size of dist/. Any error stops the build with exit code 1. Start the result with node dist/main.js (or npm start).

axil install

Terminal
❯axil install [packages…] [-D]
❯axil i @axiljs/queue

With package names, adds them to dependencies (or devDependencies with -D / --dev) in package.json, then runs npm install. A bare name is saved as latest, an exact version such as @axiljs/queue@0.4.2 as ^0.4.2, and tags or ranges as given. Without names it just runs npm install.

axil deploy

Terminal
❯axil deploy [--port <n>] [--replicas <n>] [--force]

Writes deploy/Dockerfile, deploy/deployment.yaml (Deployment, Service, and an optional HorizontalPodAutoscaler), deploy/deploy.sh and a .dockerignore in the project root.

OptionDescription
--port <n>Container port (default: 3000)
--replicas <n>Kubernetes replicas (default: instances.min from axil.scaling.json, else 3)
--forceOverwrite without warnings, including an existing .dockerignore

Existing deploy/ files are overwritten with a warning; .dockerignore is only created when missing (or replaced with --force). Image and resource names come from package.json name, lowercased and made DNS-safe (@org/api becomes org-api).

Always generated

  • A two-stage node:20-alpine Dockerfile: npm ci + npm run build, then a production stage with npm ci --production and dist/. It sets NODE_ENV=production, PORT and HOST=0.0.0.0 (containers must listen on all interfaces) and runs node dist/main.js.
  • Environment NODE_ENV, PORT and HOST=0.0.0.0 in the manifest.
  • Liveness probe on /health/live and readiness probe on /health/ready. Make sure your app serves both (the microservice, live-dashboard and high-scale-api templates do).
  • A Service on port 80 targeting the container port.

Sized from axil.scaling.json

When the project root has an axil.scaling.json (see Capacity), axil deploy prints Using axil.scaling.json and sizes the deployment from it:

Manifest fieldSource
replicashorizontal.instances.min (unless --replicas is given)
HorizontalPodAutoscalerAdded when instances.max is above the replica count: maxReplicas = instances.max, CPU target = 100 / (1 + headroom) % (77% with the default headroom of 0.3)
Pod resources (requests = limits)horizontal.instanceSize: cpus and memoryGb as Gi (only when instanceSize is set)
AXIL_WORKERS envThe pod's CPU count when vertical.workers is auto (inside a CPU-limited pod auto would see the node's cores), otherwise the configured number
terminationGracePeriodSecondsvertical.shutdownTimeoutMs rounded up to seconds, + 5
DockerfileAlso copies axil.scaling.json into the image, so serve() applies the worker, connection and shutdown limits in the container

An invalid axil.scaling.json stops the command with the reason. Without the file you get 3 replicas and no autoscaler, resources, AXIL_WORKERS or grace period.

Terminal
❯axil deploy
❯axil deploy --port=8080 --replicas=2
❯axil deploy --force

Then build and run the image from the project root:

Terminal
❯npm run build
❯docker build -f deploy/Dockerfile -t my-api .
❯docker run -p 3000:3000 my-api

deploy/deploy.sh does the build with the version tag from package.json and runs kubectl apply -f deploy/deployment.yaml.

axil doctor

Terminal
❯axil doctor

Runs quick checks and shows them in a Diagnostics card with a passed/total count:

CheckPasses when
Node.js versionNode.js 18 or newer is running (AxilJS packages themselves need 20+)
TypeScriptnpx tsc --version works
package.json, tsconfig.json, src/main.tsThe file exists
@axiljs/core dependencyListed in dependencies or devDependencies
Lock filepackage-lock.json, axil.lock or @axiljs.lock exists
.env protected.gitignore mentions .env

Version and help

Terminal
❯axil --version # @axiljs/cli v0.4.2
❯axil --help
❯axil <command> --help

Was this page helpful?

Help improve the documentation

AxilJS is open source and documentation improvements are welcome.

AxilJS DocumentationMIT License · Built by SyntaxilitY