Introduction
Midway is a Node.js framework designed for enterprise applications. It uses TypeScript decorators and an inversion-of-control container to organize business logic, making large codebases easier to maintain. It supports multiple communication protocols and can deploy to traditional servers or serverless platforms.
What Midway Does
- Provides decorator-based routing and dependency injection for HTTP APIs
- Supports gRPC, WebSocket, RabbitMQ, and Kafka alongside REST
- Runs on Express, Koa, or Fastify as the underlying HTTP engine
- Deploys to serverless platforms (AWS Lambda, Alibaba Cloud FC) without code changes
- Includes built-in support for task scheduling, caching, and validation
Architecture Overview
Midway is built around an IoC container that manages the lifecycle of services, controllers, and middleware. Decorators annotate classes to register them as injectable providers. At startup, the framework scans for decorated classes, resolves the dependency graph, and binds routes to controller methods. An adapter layer abstracts the HTTP engine, letting teams switch between Koa and Express without modifying application code.
Self-Hosting & Configuration
- Scaffold a project:
npm init midway@latest - Configure via
src/config/config.default.tswith environment-specific overrides - Select the HTTP engine (Koa, Express, or Fastify) in the bootstrap file
- Use the
@midwayjs/ormpackage for TypeORM or Sequelize integration - Deploy as a Docker container or as a serverless function bundle
Key Features
- Full TypeScript support with strong typing across the IoC container
- Multi-protocol support lets one codebase handle HTTP, gRPC, and message queues
- Serverless adapter enables deployment to cloud functions without refactoring
- Request-scoped injection isolates per-request state automatically
- Extensible decorator system for custom annotations and AOP-style middleware
Comparison with Similar Tools
- NestJS — Similar decorator and DI patterns; Midway has tighter serverless integration and multi-protocol support
- Egg.js — Convention-over-configuration from Alibaba; Midway adds DI and TypeScript-first design
- Fastify — Focused on HTTP performance; Midway wraps Fastify and adds structure for large teams
- Express — Minimal and unopinionated; Midway provides the architecture Express leaves to the developer
FAQ
Q: How does Midway compare to NestJS? A: Both use decorators and DI. Midway supports multiple HTTP engines and has built-in serverless adapters. NestJS has a larger Western community.
Q: Can I use Midway with an existing Express app? A: Yes. Midway can mount on an existing Express instance as middleware.
Q: Does Midway support GraphQL?
A: Yes. The @midwayjs/graphql component provides Apollo Server integration.
Q: What Node.js versions are required? A: Midway v3 requires Node.js 14 or later. Check the release notes for the latest requirements.