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
npm i --save-dev typescript @types/node
npx tsc --initpnpm init
pnpm i @meghjs/core reflect-metadata
pnpm i --save-dev typescript @types/node
pnpm tsc --inityarn init -y
yarn add @meghjs/core reflect-metadata
yarn add --dev typescript @types/node
yarn tsc --initValidation 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.
{
"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 |
| Websockets | socket.io, fastify-socket.io |
@react islands in views | @swc/core |
| Image transforms | sharp |
| Pretty dev logs | pino-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:
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 itThe 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.