Installation
Megh requires Node.js 22 or newer.
Using the CLI
If you already installed @meghjs/cli globally then run the following command:
megh new myapielse you can install using npx:
npx @meghjs/cli new myapipnpm dlx @meghjs/cli new myapiyarn dlx @meghjs/cli new myapiThe 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.
cd myapi
npm run start:devThe 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| Script | Description |
|---|---|
start:dev | Start the dev server with hot reload |
build | Compile TypeScript to JavaScript |
start | Start the production server |
test | Run unit tests |
Manual setup
Go to your desired project directory and run the following commands:
mkdir myapi && cd myapi && mkdir srcNew-Item -ItemType Directory -Name myapi
Set-Location myapi
New-Item -ItemType Directory -Name srcnpm init -y
npm i @meghjs/core reflect-metadata class-validator class-transformer
npm i --save-dev typescript @types/node
npx tsc --initpnpm init
pnpm i @meghjs/core reflect-metadata class-validator class-transformer
pnpm i --save-dev typescript @types/node
pnpm tsc --inityarn init -y
yarn add @meghjs/core reflect-metadata class-validator class-transformer
yarn add --dev typescript @types/node
yarn tsc --initSince 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.
{
"compilerOptions": {
"experimentalDecorators": true,
"emitDecoratorMetadata": true
}
}Then add a minimal entry point:
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:
npm i -D @meghjs/cli
npx megh serveOptional 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:
| Feature | Package |
|---|---|
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 |
| Queues | bullmq, ioredis (not needed with the memory/sync drivers) |
| Redis cache | ioredis |
| Websockets | socket.io, fastify-socket.io |
| Image transforms | sharp |
| Pretty dev logs | pino-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.