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 class-validator class-transformer
npm i --save-dev typescript @types/node
npx tsc --init
sh
pnpm init
pnpm i @meghjs/core reflect-metadata class-validator class-transformer
pnpm i --save-dev typescript @types/node
pnpm tsc --init
sh
yarn init -y
yarn add @meghjs/core reflect-metadata class-validator class-transformer
yarn add --dev typescript @types/node
yarn tsc --init

Since 0.3, class-validator and class-transformer are peer dependencies. The package loads them at import time, so install them in every project, even if your DTOs use Megh's own validation 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
Queuesbullmq, ioredis (not needed with the memory/sync drivers)
Redis cacheioredis
Websocketssocket.io, fastify-socket.io
Image transformssharp
Pretty dev logspino-pretty (dev dependency)

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.