Convert Figma logo to code with AI

midwayjs logomidway

🍔 A Node.js Serverless Framework for front-end/full-stack developers. Build the application for next decade. Works on AWS, Alibaba Cloud, Tencent Cloud and traditional VM/Container. Super easy integrate with React and Vue. 🌈

7,327
571
7,327
127

Top Related Projects

66,731

A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript 🚀

18,867

🥚 Born to build better enterprise frameworks and apps with Node.js & Koa

35,113

Expressive middleware for node.js using ES2017 async functions

64,773

Fast, unopinionated, minimalist web framework for node.

31,844

Fast and low overhead web framework, for Node.js

15,054

The API and real-time application framework

Quick Overview

Midway is a Node.js framework developed by Alibaba, designed for building enterprise-grade applications. It combines the best practices of both object-oriented programming and functional programming, offering a flexible and scalable solution for developing web applications and microservices.

Pros

  • Supports both TypeScript and JavaScript, providing type safety and better developer experience
  • Offers a modular architecture, allowing for easy integration of various components and plugins
  • Provides built-in dependency injection, making it easier to manage and test application components
  • Includes support for both traditional MVC and serverless architectures

Cons

  • Steeper learning curve compared to simpler Node.js frameworks like Express
  • Documentation is primarily in Chinese, which may be challenging for non-Chinese speakers
  • Smaller community compared to more established frameworks like Express or Nest.js
  • Some advanced features may be overkill for smaller projects

Code Examples

  1. Creating a simple controller:
import { Controller, Get } from '@midwayjs/decorator';

@Controller('/')
export class HomeController {
  @Get('/')
  async home() {
    return 'Hello Midway!';
  }
}
  1. Using dependency injection:
import { Provide, Inject } from '@midwayjs/decorator';

@Provide()
export class UserService {
  async getUser(id: number) {
    // Fetch user logic
  }
}

@Provide()
export class UserController {
  @Inject()
  userService: UserService;

  async getUser(id: number) {
    return this.userService.getUser(id);
  }
}
  1. Creating a middleware:
import { Middleware } from '@midwayjs/decorator';
import { IMiddleware } from '@midwayjs/core';

@Middleware()
export class ReportMiddleware implements IMiddleware {
  resolve() {
    return async (ctx, next) => {
      const startTime = Date.now();
      await next();
      console.log(`Request took ${Date.now() - startTime}ms`);
    };
  }
}

Getting Started

To start a new Midway project:

  1. Install the Midway CLI:

    npm install -g @midwayjs/cli
    
  2. Create a new project:

    midway-init my-midway-app
    
  3. Navigate to the project directory and install dependencies:

    cd my-midway-app
    npm install
    
  4. Start the development server:

    npm run dev
    

Your Midway application is now running at http://localhost:7001.

Competitor Comparisons

66,731

A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript 🚀

Pros of Nest

  • Larger community and ecosystem, with more third-party packages and resources
  • More comprehensive documentation and learning materials
  • Better support for microservices architecture out of the box

Cons of Nest

  • Steeper learning curve, especially for developers new to TypeScript or decorators
  • Heavier framework with more boilerplate code
  • Potentially slower startup time due to its dependency injection system

Code Comparison

Nest:

@Controller('cats')
export class CatsController {
  @Get()
  findAll(): string {
    return 'This action returns all cats';
  }
}

Midway:

@Provide()
@Controller('/cats')
export class CatsController {
  @Get('/')
  async findAll(): Promise<string> {
    return 'This action returns all cats';
  }
}

Both frameworks use decorators for defining controllers and routes, but Midway requires the @Provide() decorator for dependency injection. Nest's approach is slightly more concise, while Midway's is more explicit about its DI system.

Nest and Midway are both TypeScript-based Node.js frameworks, but they cater to different preferences and use cases. Nest is more popular and feature-rich, while Midway offers a simpler learning curve and faster development for certain scenarios.

18,867

🥚 Born to build better enterprise frameworks and apps with Node.js & Koa

Pros of Egg

  • More mature and established ecosystem with a larger community
  • Extensive plugin system for easy extensibility
  • Strong focus on convention over configuration

Cons of Egg

  • Primarily uses JavaScript, which may lack some TypeScript benefits
  • Less flexible for non-traditional project structures
  • Steeper learning curve for developers new to the framework

Code Comparison

Egg:

// app/controller/home.js
'use strict';

const Controller = require('egg').Controller;

class HomeController extends Controller {
  async index() {
    this.ctx.body = 'Hello world';
  }
}

module.exports = HomeController;

Midway:

// src/controller/home.ts
import { Controller, Get } from '@midwayjs/decorator';

@Controller('/')
export class HomeController {
  @Get('/')
  async home(): Promise<string> {
    return 'Hello world';
  }
}

Midway offers a more modern, TypeScript-first approach with decorators, while Egg follows a more traditional JavaScript class-based structure. Midway's syntax is more concise and leverages TypeScript features, potentially leading to improved developer experience and type safety. However, Egg's approach may be more familiar to developers coming from other Node.js frameworks.

35,113

Expressive middleware for node.js using ES2017 async functions

Pros of Koa

  • Lightweight and minimalist framework, offering flexibility and customization
  • Excellent performance due to its small footprint and efficient middleware system
  • Large ecosystem with numerous plugins and middleware available

Cons of Koa

  • Requires more setup and configuration for complex applications
  • Less opinionated, which may lead to inconsistencies in large projects
  • Steeper learning curve for beginners due to its minimalist nature

Code Comparison

Koa:

const Koa = require('koa');
const app = new Koa();

app.use(async ctx => {
  ctx.body = 'Hello World';
});

app.listen(3000);

Midway:

import { Controller, Get, Provide } from '@midwayjs/decorator';

@Provide()
@Controller('/')
export class HomeController {
  @Get('/')
  async home() {
    return 'Hello World';
  }
}

Key Differences

  • Midway uses TypeScript and decorators for a more structured approach
  • Koa relies on middleware chaining, while Midway uses a more traditional MVC pattern
  • Midway provides built-in dependency injection and IoC container
  • Koa offers more flexibility in application structure, while Midway enforces a specific architecture

Both frameworks have their strengths, with Koa excelling in simplicity and flexibility, and Midway providing a more opinionated and feature-rich environment for enterprise-level applications.

64,773

Fast, unopinionated, minimalist web framework for node.

Pros of Express

  • Lightweight and minimalist framework, offering flexibility and simplicity
  • Extensive ecosystem with a wide range of middleware and plugins
  • Well-established community support and extensive documentation

Cons of Express

  • Lacks built-in TypeScript support, requiring additional setup
  • No built-in dependency injection or modular architecture
  • Limited out-of-the-box features compared to more opinionated frameworks

Code Comparison

Express:

const express = require('express');
const app = express();

app.get('/', (req, res) => {
  res.send('Hello World!');
});

Midway:

import { Controller, Get } from '@midwayjs/decorator';

@Controller('/')
export class HomeController {
  @Get('/')
  async home() {
    return 'Hello World!';
  }
}

Express offers a more straightforward approach with less boilerplate, while Midway provides a more structured, decorator-based setup with built-in TypeScript support. Midway's approach aligns with modern TypeScript practices and offers better type safety out of the box. Express, being more lightweight, allows for greater flexibility in structuring applications but requires additional setup for TypeScript integration and advanced features.

31,844

Fast and low overhead web framework, for Node.js

Pros of Fastify

  • Extremely high performance, often outperforming other Node.js frameworks
  • Extensive plugin ecosystem for easy extensibility
  • Built-in support for JSON Schema validation

Cons of Fastify

  • Steeper learning curve for developers new to the framework
  • Less opinionated, requiring more setup for complex applications

Code Comparison

Fastify:

const fastify = require('fastify')()

fastify.get('/', async (request, reply) => {
  return { hello: 'world' }
})

fastify.listen(3000)

Midway:

import { Controller, Get, Provide } from '@midwayjs/decorator';

@Provide()
@Controller('/')
export class HomeController {
  @Get('/')
  async home() {
    return { hello: 'world' };
  }
}

Key Differences

  • Fastify focuses on high performance and low overhead
  • Midway is built on top of Node.js frameworks like Express or Koa
  • Fastify uses a plugin system for extensibility
  • Midway leverages TypeScript and decorators for a more structured approach
  • Fastify is more lightweight and flexible
  • Midway provides a more comprehensive, full-stack solution

Both frameworks have their strengths, with Fastify excelling in performance and simplicity, while Midway offers a more structured, full-featured development experience.

15,054

The API and real-time application framework

Pros of Feathers

  • More mature and established ecosystem with a larger community
  • Supports real-time events and WebSocket out of the box
  • Flexible and modular architecture allowing easy customization

Cons of Feathers

  • Steeper learning curve for developers new to its concepts
  • Less opinionated, which may lead to inconsistent code structures across projects
  • Limited built-in support for GraphQL compared to Midway

Code Comparison

Feathers service creation:

const feathers = require('@feathersjs/feathers');
const app = feathers();

app.use('messages', {
  async find() {
    return [{ id: 1, text: 'Hello' }];
  }
});

Midway controller creation:

import { Controller, Get } from '@midwayjs/decorator';

@Controller('/api')
export class HomeController {
  @Get('/')
  async home() {
    return 'Hello Midway!';
  }
}

Both frameworks offer straightforward ways to create services or controllers. Feathers uses a more functional approach, while Midway leverages decorators for a more declarative style. Feathers' simplicity in service creation contrasts with Midway's TypeScript-first approach, which provides stronger typing and better IDE support out of the box.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Midway Logo

Midway - 一个面向未来的云端一体 Node.js 框架

GitHub license GitHub tag Build Status Test Coverage lerna PRs Welcome Gitpod Ready-to-Code Code Style: MidwayJS Leaderboard

English | 简体中文

资源

特性

  • 🐘 全功能:支持 Web 应用/Serverless/FaaS/微服务/小程序后端等多种场景,基于装饰器和依赖注入开发企业级应用
  • 🐦 前端集成:全新的云端一体应用研发体验,零 API 调用,使用 "React Hooks " 风格一体研发
  • 🐴 **跨平台**:支持部署至普通 Server 或 Serverless/FaaS 环境
  • 🐶 扩展:组件化扩展能力,另外支持使用 Koa/Express/Egg.js 生态插件
  • 🐂 示例: 官方提供多种场景的示例代码,方便开发者快速上手
  • 🛡 TypeScript 全面支持

描述

Midway 是一个适用于构建 Serverless 服务,传统应用、微服务,小程序后端的 Node.js 框架。

Midway 可以使用 Koa,Express 或 Egg.js 作为基础 Web 框架。它还提供了独立使用的基本解决方案,例如 Socket.io,GRPC,Dubbo.js 和 RabbitMQ 等。

此外,Midway 也适用于前端/全栈开发人员的 Node.js 无服务器框架。构建下一个十年的应用程序。可在 AWS,阿里云,腾讯云和传统 VM /容器上运行。与 React 和 Vue 轻松集成。 🌈

Demo

使用装饰器开发 Web 应用

import { Controller, Get, Provide } from '@midwayjs/decorator';

@Provide()
@Controller('/')
export class HomeController {

  @Get('/')
  async home() {
    return `Welcome to midwayjs!`;
  }
}

使用函数开发全栈应用

后端代码 src/apis/lambda/index.ts

import {
  Api,
  Get,
  Query,
  useContext,
} from '@midwayjs/hooks';

export default Api(
  Get(),
  Query<{
    page: string;
    limit: string;
  }>(),
  async () => {
    const ctx = useContext();
    return {
      page: ctx.query.page,
      limit: ctx.query.limit,
    };
  }
);

前端调用 src/page/index.tsx

import getArticles from './api';
const response = await getArticles({
  query: { page: '0', limit: '10' },
});
console.log(response); // { page: '0', limit: '10' }

手动调用

fetch('/api/articles?page=0&limit=10')
  .then((res) => res.json())
  .then((res) => console.log(res)); // { page: '0', limit: '10' }

快速上手

$ npm -v

## 选择模版
$ npm init midway

## 进入项目路径
cd my_midway_app && npm run dev

文档和社区

社区优秀示例展示

1、Cool-Admin - 一个很酷的后台权限管理框架

image

VSC Plugin

答疑

群里会有热心的朋友,也会有新版本发布推送。

贡献

请告知我们可以为你做些什么,不过在此之前,请检查一下是否有 已经存在的Bug或者意见。

如果你是一个代码贡献者,请参考代码贡献规范。

谁在使用

image 你也想加 Logo ?可以点击 这里 添加。

License

我们的代码使用 MIT 协议,请放心使用。

FOSSA Status

NPM DownloadsLast 30 Days