Docs for the next release (prerelease). Install it with npm i @meghjs/cli@next. Latest release docs →

Next release (prerelease) · Latest docs →

Skip to content

Installation ​

Megh requires Node.js 22 or newer.

Using the CLI ​

If you already installed @meghjs/cli globally then run the following command:

sh
megh new myapi

else you can install using npx:

sh
npx @meghjs/cli new myapi
sh
pnpm dlx @meghjs/cli new myapi
sh
yarn dlx @meghjs/cli new myapi

The CLI asks which package manager to use and which features to include — OpenAPI docs, CORS and MeghORM — then scaffolds the project and installs its dependencies.

sh
cd myapi
npm run start:dev

The app starts on http://localhost:4000, and with OpenAPI enabled the docs are served at /docs.

What you get ​

myapi/
├── src/
│   ├── controllers/     # Route controllers
│   ├── services/        # Business logic
│   ├── config/          # App configuration
│   ├── app.ts           # App setup
│   └── serve.ts         # Entry point
├── test/
├── tsconfig.json
└── package.json
ScriptDescription
start:devStart the dev server with hot reload
buildCompile TypeScript to JavaScript
startStart the production server
testRun unit tests

Manual setup ​

Go to your desired project directory and run the following commands:

sh
mkdir myapi && cd myapi &&  mkdir src
powershell
New-Item -ItemType Directory -Name myapi
Set-Location myapi
New-Item -ItemType Directory -Name src
sh
npm init -y
npm i @meghjs/core reflect-metadata
npm i --save-dev typescript @types/node
npx tsc --init
sh
pnpm init
pnpm i @meghjs/core reflect-metadata
pnpm i --save-dev typescript @types/node
pnpm tsc --init
sh
yarn init -y
yarn add @meghjs/core reflect-metadata
yarn add --dev typescript @types/node
yarn tsc --init

Validation decorators come from @meghjs/core, so class-validator and class-transformer are not needed. They are optional peers: install them only to keep DTOs written with their decorators.

Ensure experimentalDecorators and emitDecoratorMetadata are enabled in tsconfig.json — Megh's decorators do not work without them.

json
{
  "compilerOptions": {
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
  }
}

Then add a minimal entry point:

ts
import { Megh } from '@meghjs/core';

const app = Megh.createApplication();

app.mapGet('/', () => 'Welcome to Megh.');

app.run();

You can still use the CLI's generators and dev server in a manually created project by installing it locally:

sh
npm i -D @meghjs/cli
npx megh serve

Optional dependencies ​

Install these only for the features you use. Without them the package still imports, and you get a clear install hint the moment a feature needs one:

FeaturePackage
CORS (useCors)@fastify/cors
File uploads (useMultipart, @UploadFile)@fastify/multipart
Static files (useStaticFiles)@fastify/static
OpenAPI with Swagger UI@fastify/swagger, @fastify/swagger-ui
OpenAPI with Scalar@fastify/swagger, @scalar/fastify-api-reference
@IsUUID, @IsUrl, @IsEmail(options)validator
Models and migrations (useMeghORM)a driver: pg, mysql2, better-sqlite3, or tedious + tarn
TypeORM (alternative to MeghORM)@meghjs/data, typeorm + a driver (pg, mysql2, sqlite3, better-sqlite3, mssql)
Knex (alternative to MeghORM)@meghjs/data, knex + a driver
Websocketssocket.io, fastify-socket.io
@react islands in views@swc/core
Image transformssharp
Pretty dev logspino-pretty (dev dependency)

Queues, messaging, the Redis cache and the Redis rate limit store need nothing extra: BullMQ, the Redis client (@redis/client) and the RabbitMQ client (amqplib) are dependencies of @meghjs/core.

Trying the next release ​

npm install gives you the latest release. Before a new release is final, prereleases of it (versions like 0.8.0-next.0) are published under the next tag:

sh
npx @meghjs/cli@next new myapi     # a new project on the next release
npm install @meghjs/core@next @meghjs/cli@next   # move a project to it

The docs for the next release cover the new APIs, and its upgrade guide lists the breaking changes. A version range such as ^0.7.3 never installs a prerelease, so npm update keeps you on the latest release until you choose @next.

Module format ​

@meghjs/core ships a single CommonJS build. ESM projects can still import { ... } from '@meghjs/core'. Only the package root is exported: deep imports such as @meghjs/core/dist/... are not supported.

Released under the MIT License.