Skip to content

CLI ​

Install the CLI globally, or run it with npx:

sh
npm i -g @meghjs/cli

Command Overview ​

CommandAliasDescription
newCreate a new application
serveStart the dev server with watch + rebuild
buildCompile using tsconfig.build.json
make:modelm:mCreate a model: a plain class, a MeghORM model with --orm (columns from its migrations), or a TypeORM entity with --typeorm
sync:models:mSync an existing model's columns with its migrations (was update:model)
make:resourcem:rCreate a REST resource for a model: DTOs, CRUD service and controller
make:controllerm:cCreate a controller
make:servicem:sCreate a service
make:configm:cnfCreate a config class
make:middlewarem:mlwrCreate a middleware
make:mailm:mailCreate a Mailable in src/mail/
make:eventm:evCreate an event in src/events/
make:listenerm:lsnCreate an event listener in src/listeners/ (--event to type it)
make:queuem:qCreate a queue with a job handler in src/queues/
make:workerm:wCreate a worker for a queue in src/workers/
make:taskm:task, make:schedulerCreate a scheduled task in src/tasks/ (--cron, --interval)
make:dtom:dtoCreate a class-validator DTO in src/dtos/
make:classm:clsCreate a plain class in src/classes/
make:testm:tCreate a unit test (<name>.spec.ts) for an existing file
make:migrationm:migCreate a database migration
make:seederm:sdCreate a database seeder
make:factorym:fCreate a model factory with Faker values
migrateRun pending migrations (--seed to seed afterwards)
migrate:statusShow which migrations have run
migrate:rollbackUndo the last migration (--step <n> for more)
migrate:resetUndo every migration
migrate:refreshUndo every migration, then run them all again (--seed too)
db:seedRun the seeders (--seeder <name> for one)
scaffold:domainsc:domainCreate the tables and models (or resources) of a business domain
scaffold:authsc:authAdd sign-up and sign-in with JWTs and/or API keys, optionally with roles
scaffold:rbacsc:rbacAdd roles and permissions to an app's users
template:listtemplatesList the model templates

Every make:* command takes -f / --force to overwrite an existing file. The generators except make:model and the database ones (make:migration, 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 ​

PageCommands
Generatorsmake: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 Commandsmake:migration, migrate*, make:seeder, db:seed, make:factory
Scaffold--template, --fields, scaffold:domain, scaffold:auth, scaffold:rbac, template:list

Version and info ​

sh
npx megh -v       # the Megh logo and the CLI version (also --version)
npx megh --info   # the logo, CLI, Node.js and OS versions, and the project's Megh packages

The logo appears only here; megh --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 ​

sh
npx @meghjs/cli new myapi

You 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:

sh
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/.

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:

sh
cd myapi
npm run start:dev

Development Server ​

sh
npx megh serve

Compiles 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.

Build ​

sh
npx megh build

Removes the output folder (outDir, usually dist/) and compiles the project with tsconfig.build.json.

Released under the MIT License.