AxilJS Project Commands
Reference for every axil project command in AxilJS 0.4.2: create, generate, migrate, run, test, build, install, deploy, doctor.
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
Creates a new project in ./<name>, writes the files, runs npm install and prints numbered next steps.
| Option | Description |
|---|---|
-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, --yes | Accept defaults for every option not given as a flag (no prompts) |
--db <driver> | none (default), sqlite, postgres, mysql |
--auth / --no-auth | JWT + RBAC auth (default: on) |
--ai | Include the AI platform (default: off) |
--ws | Include WebSocket support (default: off) |
--queue | Include Queue and Scheduler (default: off) |
--skip-install | Do not run npm install |
--force | Allow creating into an existing non-empty directory |
Interactive flow
On a terminal, anything you did not pass is asked for in four steps:
- 1/4 Project name: only when no name was given. Letters, numbers,
.,-,_; it cannot start with.or-. - 2/4 Template picker: categories Start, APIs, Realtime, Background, AI, Production and Custom.
↑↓move (and flow across categories at the ends),←→ortabswitch category,space/enterselect,/searches every category,escleaves the search or cancels. - 3/4 Database and features: only for Custom. A database select, then one multi-select for Authentication, WebSocket, Queue and AI platform.
- 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
--yesthere are no prompts and a name is required. --templatecannot be combined with--db,--auth,--ai,--wsor--queue. Giving any of those flags without--templateskips 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,typescriptand@types/nodeas devDependencies, soaxil runcan start Studio andnpm testworks 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 installfails, the CLI says where the partial project was left so you can remove it before retrying.
axil generate
Generates files in the layout axil create uses:
| Kind | Files |
|---|---|
module | src/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 |
controller | src/modules/<name>/controllers/<name>.controller.ts |
service | src/modules/<name>/services/<name>.service.ts |
entity | src/modules/<name>/entities/<name>.entity.ts |
migration | src/migrations/<NNN>_<name>.ts (the next free number) |
| Option | Description |
|---|---|
--force | Overwrite files that already exist (otherwise they are skipped with a warning) |
--db <driver> | Database driver for the templates (default: detected from package.json) |
--auth | Protect the list route with authenticate() (default: detected from package.json) |
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
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:
| Variable | Meaning |
|---|---|
DB_DRIVER | sqlite, postgres or mysql (optional; inferred otherwise) |
DATABASE_URL | postgres://… or mysql://… connection string |
DATABASE_FILENAME | SQLite 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.
| Option | Description |
|---|---|
--dir <path> | Migrations directory (default: src/migrations) |
--check | Check migrations for locking and breaking changes; runs nothing. Same as axil migrate check |
--all | With --check: analyze every migration, not only pending ones |
--json | With --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.
--safety | Behaviour of up |
|---|---|
off | No check (the default without a project setting) |
warn | Prints the findings, then migrates |
block | Prints 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:
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:
┌ 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:
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}| Field | Description |
|---|---|
ok | false when any finding is an error |
driver | sqlite, postgres or mysql |
scope | pending, or all with --all |
offline | true when no database was used and every migration was treated as pending |
counts | Migrations analyzed, findings, and findings per severity |
migrations | Per migration: name, project-relative file, number of captured statements, and findings (errors first) with rule, severity, table, lock, statement, message, fix |
Exit codes.
| Code | When |
|---|---|
0 | --check found no error (warnings and info do not fail); up, down and status succeeded |
1 | --check found at least one error finding |
1 | up --safety=block refused to run |
1 | Any other failure: no database configured, migrations directory not found, an invalid flag value, a failing migration |
In CI:
1- run: npm ci
2- run: npx axil migrate --check
3 env:
4 DB_DRIVER: postgresaxil run
The development server. It takes no options.
- Checks for
package.json,tsconfig.jsonandsrc/. - Compiles with
tsc --incremental --noEmitOnError. - Starts the first entry it finds:
dist/main.js,dist/server.js,dist/index.js, or the same names underdist/src/. - Starts Studio on the app port + 1. The app port is
PORTfrom.env(default 3000). - Watches
src/for.ts/.tsxchanges, recompiles and restarts the app. Compile errors are printed and the running app is left alone until the next save.
12:04:31 ✔ Restarted in 320ms src/app.ts · #1If @axiljs/studio cannot be found (project node_modules first), axil run keeps going without it and prints:
→ Studio skipped @axiljs/studio not installed: npm install -D @axiljs/studioProjects 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
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.
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
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
Writes deploy/Dockerfile, deploy/deployment.yaml (Deployment, Service, and an optional HorizontalPodAutoscaler), deploy/deploy.sh and a .dockerignore in the project root.
| Option | Description |
|---|---|
--port <n> | Container port (default: 3000) |
--replicas <n> | Kubernetes replicas (default: instances.min from axil.scaling.json, else 3) |
--force | Overwrite 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-alpineDockerfile:npm ci+npm run build, then a production stage withnpm ci --productionanddist/. It setsNODE_ENV=production,PORTandHOST=0.0.0.0(containers must listen on all interfaces) and runsnode dist/main.js. - Environment
NODE_ENV,PORTandHOST=0.0.0.0in the manifest. - Liveness probe on
/health/liveand readiness probe on/health/ready. Make sure your app serves both (themicroservice,live-dashboardandhigh-scale-apitemplates 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 field | Source |
|---|---|
replicas | horizontal.instances.min (unless --replicas is given) |
| HorizontalPodAutoscaler | Added 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 env | The 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 |
terminationGracePeriodSeconds | vertical.shutdownTimeoutMs rounded up to seconds, + 5 |
| Dockerfile | Also 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.
Then build and run the image from the project root:
deploy/deploy.sh does the build with the version tag from package.json and runs kubectl apply -f deploy/deployment.yaml.
axil doctor
Runs quick checks and shows them in a Diagnostics card with a passed/total count:
| Check | Passes when |
|---|---|
| Node.js version | Node.js 18 or newer is running (AxilJS packages themselves need 20+) |
| TypeScript | npx tsc --version works |
package.json, tsconfig.json, src/main.ts | The file exists |
@axiljs/core dependency | Listed in dependencies or devDependencies |
| Lock file | package-lock.json, axil.lock or @axiljs.lock exists |
.env protected | .gitignore mentions .env |
Version and help
Was this page helpful?