CLI
Install the CLI globally, or run it with npx:
npm i -g @meghjs/cliCommand Overview
| Command | Alias | Description |
|---|---|---|
new | Create a new application | |
add | Add views, a Vite frontend or Inertia to an existing project | |
serve | Start the dev server with watch + rebuild | |
build | Compile using tsconfig.build.json | |
make:model | m:m | Create a model: a plain class, a MeghORM model with --orm (columns from its migrations), or a TypeORM entity with --typeorm |
sync:model | s:m | Sync an existing model's columns with its migrations (was update:model) |
make:resource | m:r | Create a REST resource for a model: DTOs, CRUD service and controller |
make:controller | m:c | Create a controller |
make:service | m:s | Create a service |
make:config | m:cnf | Create a config class |
make:middleware | m:mlwr | Create a middleware |
make:mail | m:mail | Create a Mailable in src/mail/ |
make:event | m:ev | Create an event in src/events/ |
make:listener | m:lsn | Create an event listener in src/listeners/ (--event to type it) |
make:queue | m:q | Create a queue with a job handler in src/queues/ |
make:worker | m:w | Create a worker for a queue in src/workers/ |
make:task | m:task, make:scheduler | Create a scheduled task in src/tasks/ (--cron, --interval) |
make:dto | m:dto | Create a DTO in src/dtos/ |
make:class | m:cls | Create a plain class in src/classes/ |
make:view | m:v | Create a .megh.html view (or -c component) in views/ |
make:page | m:p | Create an Inertia page (Vue, React or Svelte) in frontend/pages/ |
make:test | m:t | Create a unit test (<name>.spec.ts) for an existing file |
make:migration | m:mig | Create a database migration |
make:messaging | Create the migration for the messaging tables (outbox, scheduler locks, dedupe) | |
make:seeder | m:sd | Create a database seeder |
make:factory | m:f | Create a model factory with Faker values |
migrate | Run pending migrations (--seed to seed afterwards) | |
migrate:status | Show which migrations have run | |
migrate:rollback | Undo the last migration (--step <n> for more) | |
migrate:reset | Undo every migration | |
migrate:refresh | Undo every migration, then run them all again (--seed too) | |
db:seed | Run the seeders (--seeder <name> for one) | |
messaging:failed | List messages that failed after their retries, or retry / discard them. See Messaging | |
scaffold:domain | sc:domain | Create the tables and models (or resources) of a business domain |
scaffold:auth | sc:auth | Add sign-up and sign-in with JWTs and/or API keys, optionally with roles |
scaffold:rbac | sc:rbac | Add roles and permissions to an app's users |
template:list | templates | List the model templates |
make:agents | Write AGENTS.md (and a CLAUDE.md that imports it) for coding agents |
Every make:* command takes -f / --force to overwrite an existing file. The generators except make:model and the database ones (make:migration, make:messaging, make:seeder, make:factory) also write a unit test next to the file; pass --notest (or -nt) to skip it. See Tests. make:model and make:resource also build the table from a template with --template or --fields.
Pages
| Page | Commands |
|---|---|
| Generators | make:resource, make:controller, make:service, make:model, sync:model, make:middleware, make:config, make:mail, make:event, make:listener, make:queue, make:worker, make:task, make:dto, make:class, make:test |
| Database Commands | make:migration, make:messaging, migrate*, make:seeder, db:seed, make:factory |
| Messaging | messaging:failed |
| Scaffold | --template, --fields, scaffold:domain, scaffold:auth, scaffold:rbac, template:list |
Version and info
npx megh -v # the CLI version, e.g. 0.7.3 (also --version)
npx megh --info # the logo, CLI, Node.js and OS versions, and the project's Megh packages (also -i)The logo appears only with --info; -v, --help and the other commands print without it. --info also shows the installed @meghjs/core, @meghjs/data and TypeScript versions when run inside an app: paste it into a bug report.
Application
npx @meghjs/cli new myapiYou are prompted for a package manager and optional features: OpenAPI docs, CORS and MeghORM. With MeghORM you also pick the database. Add Mail, Scalar UI or the @meghjs/data plugin afterwards. Non-interactively:
npx @meghjs/cli new myapi --yes --database postgres # also: mysql, sqlite, mssql--database (or the orm feature, which defaults to SQLite) installs the driver, adds app.useMeghORM() to src/app.ts, writes DATABASE_URL to .env and creates src/database/migrations/.
For a server-rendered app, pass --mvc:
npx @meghjs/cli new myapp --mvcIt adds app.useViews() and app.useMethodOverride() to src/app.ts, a layout in views/layouts/app.megh.html, a page in views/pages/home.megh.html, and a HomeController that renders it with Results.View('pages.home', ...). Add more pages with make:view. See Views. --mvc can't be combined with --minimal.
For a single-page app with Inertia.js, pass --inertia and optionally the frontend framework (vue by default, react or svelte):
npx @meghjs/cli@next new myapp --inertia # Vue
npx @meghjs/cli@next new myapp --inertia reactIt adds useViews(), useVite(), useSession() and useInertia() to src/app.ts, and:
views/app.megh.html: the HTML document, with@viteand@inertiafrontend/app.ts(app.tsxfor React): the Inertia client entryfrontend/pages/Home.vue(.tsx,.svelte): the pageHomeControllerreturns withResults.Inertia('Home', ...)frontend/css/app.cssandfrontend/tsconfig.jsonvite.config.mts, which buildsfrontend/intopublic/build- a random
SESSION_SECRETin.env
megh serve builds the frontend too (see below), and npm run build runs vite build before megh build. Add pages with make:page. --inertia can't be combined with --minimal or --mvc.
--mvc and --inertia run the same steps as megh add, so a project created plain and upgraded later ends up the same.
Add to a project
Start small and add layers as the app grows. Each step only adds files and setup. It never moves your code:
npx megh add views # server-rendered .megh.html in views/
npx megh add vite # browser code in frontend/, built by Vite
npx megh add inertia [vue|react|svelte] # Inertia pages in frontend/pages/ (adds vite)| Command | Adds |
|---|---|
add views | views/layouts/app.megh.html, useViews() and useMethodOverride() |
add vite | frontend/ (app.ts, css/, tsconfig.json), vite.config.mts, useVite(), vite and @fastify/static, public/build/ in .gitignore. A layout gets @vite('frontend/app.ts') |
add inertia | Vite if missing, the framework's packages and Vite plugin, frontend/app.ts (the Inertia entry), frontend/pages/Home, views/app.megh.html, useViews(), useSession() (with SESSION_SECRET), useInertia() |
Setup goes into src/app.ts before app.useControllers(...), or before the first route in a minimal app. The commands are safe to run again: what's already there is kept, and nothing changes the second time.
Files Megh generated, such as the plain frontend/app.ts and vite.config.mts from add vite, are replaced when you haven't edited them. A vite.config you changed is patched in place (plugin and entry added). A frontend/app.ts with your code is never overwritten: move it, or pass --force.
Changes to existing files are shown as a diff before they're kept. Pass -y to skip the prompt, or --dry-run to only see them. Run your package manager's install afterwards when dependencies were added.
The project also gets an AGENTS.md: instructions for coding agents such as Claude Code, Codex, Cursor and Copilot. It lists the project's commands, where code goes, and the Megh rules that compile cleanly but fail at runtime (register new controllers, give every DTO property a validator, and so on). A CLAUDE.md containing @AGENTS.md makes Claude Code read the same file. Edit both freely: they're yours. To add them to an existing project, run npx megh make:agents (--force replaces an existing AGENTS.md; a CLAUDE.md of your own is never replaced).
The new project is put under git with git init, unless git isn't installed or the folder is already inside a repository. Pass --skip-git (or set MEGH_SKIP_GIT=1) to skip it. Then:
cd myapi
npm run start:devDevelopment Server
npx megh serveCompiles src/ with SWC into dist/, starts the app and restarts it on change. The entry point comes from megh.entry in package.json, falling back to main.
When the project has a vite.config file (after megh add vite or add inertia), serve also starts Vite's dev server. Its output is prefixed [VITE]. Edits in frontend/ then reach the open page with hot module replacement: no reload, and component state is kept. See Vite.
| Option | Effect |
|---|---|
--no-hmr | Run vite build --watch instead. Pages load the built files; reload to see changes |
--no-vite | Don't run Vite; run it yourself |
A vite.config without the megh() plugin from @meghjs/core/vite gets vite build --watch, and serve says how to turn on HMR.
Build
npx megh buildRemoves the output folder (outDir, usually dist/) and compiles the project with tsconfig.build.json.