Introduction
Megh is a TypeScript-first web framework for building REST APIs on Node.js. It runs on Fastify and gives you decorators, dependency injection, validation, an ORM and OpenAPI docs, with less boilerplate than most structured frameworks.
import { ApiController, Get, Post, Param, Body } from '@meghjs/core';
import { UserService } from '../services/user.service';
import { CreateUserDto } from '../dtos/create-user.dto';
@ApiController('/users')
export class UserController {
constructor(private readonly users: UserService) {}
@Get('/:id')
findOne(@Param('id') id: number) {
return this.users.find(id);
}
@Post('/')
create(@Body() dto: CreateUserDto) {
return this.users.create(dto); // dto is already validated
}
}import { Megh } from '@meghjs/core';
import { UserController } from './controllers/user.controller';
const app = Megh.createApplication();
app.useControllers([UserController]);
app.run();The controller gets its service through the constructor, the body is validated against CreateUserDto before the handler runs, and with app.useOpenApi() both routes appear in the generated OpenAPI document.
Who it's for
- TypeScript developers who want structure without ceremony. Controllers, services and DTOs, but no module files or provider arrays to keep in sync.
- Developers coming from Laravel, Rails or Django who miss models, migrations, seeders and generators in Node.
- Teams building business APIs, where the CLI can scaffold a working domain with auth and roles in minutes.
What's included
HTTP
- Decorator-based controllers and inline routes
- Middleware with one fixed pipeline order
- Validation with class-validator-compatible decorators, compiled once per DTO
- Authentication and deny-by-default authorization
- Error handling with exception filters
- OpenAPI documents with Swagger UI or Scalar
Application
- Dependency injection with Megh's own container
- Configuration from
.envand typed config classes - Lifecycle hooks and graceful shutdown
- Health checks, request IDs and structured logging
Data and background work
- MeghORM: typed models, a query builder, migrations, seeders and factories
- Optional TypeORM and Knex integrations through
@meghjs/data - Events, queues, scheduled tasks and caching
- File uploads with safe defaults
- WebSockets with Socket.IO
Tooling
- The
meghCLI: new projects, generators, migrations and scaffolding - Testing helpers and in-memory queue drivers
How it's built
- On Fastify. Megh adds structure on top of Fastify rather than replacing it. The Fastify instance is always available as
app.app, so any Fastify plugin works. - Install only what you use. Integrations such as CORS, OpenAPI, uploads, Redis and Socket.IO are optional peer dependencies. If one is missing, the
use*call tells you what to install. - Safe defaults.
@Authorizedroutes are denied unless an authorization handler allows them, fields a DTO doesn't declare are rejected with a 400, 5xx details are hidden in production, and uploads get random names inside a fixed folder. - CommonJS.
@meghjs/coreships one CommonJS build, which ESM projects can still import. See Installation.
How it compares
- Express and Fastify give you routing and leave structure to you. Megh adds controllers, DI, validation, an ORM and OpenAPI, on Fastify.
- NestJS is the closest in style: decorators, DI and controllers. Megh has no module system, so there's less wiring, and it ships its own ORM and scaffolding. NestJS has a much larger ecosystem and community.
- AdonisJS shares the batteries-included idea. Megh is decorator-first and runs on Fastify.
Project status
Megh is in 0.x and heading to 1.0. Minor releases can still contain breaking changes, each with an upgrade guide. See the versioning policy and upcoming changes.
On 0.5.x? See Upgrading to 0.6.
Coming from Avleon? Avleon is now Megh. See Moving from Avleon to Megh. On 0.3 or earlier, read Upgrading to 0.4 first.
Next steps
- Install Megh and create a project.
- Follow the Quick Start to write your first routes.
- Read Application to see how an app is put together.