Configs2026年5月25日·1 分钟阅读

Midway — Enterprise Node.js Framework with IoC and Decorators

Midway is a TypeScript-first Node.js framework built on dependency injection and decorators, supporting HTTP, gRPC, WebSocket, and serverless deployments from one codebase.

Agent 就绪

这个资产可以被 Agent 直接读取和安装

TokRepo 同时提供通用 CLI 命令、安装契约、metadata JSON、按适配器生成的安装计划和原始内容链接,方便 Agent 判断适配度、风险和下一步动作。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Midway Overview
通用 CLI 安装命令
npx tokrepo install 767f2500-5837-11f1-9bc6-00163e2b0d79

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.ts with environment-specific overrides
  • Select the HTTP engine (Koa, Express, or Fastify) in the bootstrap file
  • Use the @midwayjs/orm package 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.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产