npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

mango-core

v0.0.11

Published

A high-performance backend framework based on Bun and Elysia(一个基于Bun和Elysia的高性能后端框架)

Readme

Mango

npm downloads GitHub stars GitHub forks

国内文档 外网文档

简介

Mango 是一个轻量级、高性能的 Web 框架,在Elysia的基础上进行的二次开发。它在既拥有智能类型提示的情况下又提供了一套完整的mvc开发方式

特性

  • 高性能:基于 Bun 的高效运行时,提供卓越的性能。
  • 简单易用:直观的 API 设计,让开发者可以快速上手。
  • 生态:基于Elysia改造而来,完全适配Elysia的插件、中间件、生态。
  • 内置路由:灵活的路由系统,支持动态路由和中间件。
  • TypeScript 支持:内置对 TypeScript 的支持,提升开发体验。
  • 支持 WebSocket:轻松实现WebSocket功能。
  • 支持 Cron:轻松实现定时任务功能。

安装

bun add mango-core elysia mango-types

快速开始

以下是一个使用 Mango 构建基本 Web 服务器的示例:


import { Controller, Get} from 'mango-core'
import type { Context } from 'mango-types'
@Controller({
  name: '测试模块',
  prefix: '/test',
  detail: {
    description: '这是一段测试模块的备注',
    tags: ['测试'],
  },
})
export default class DemoController {
  @Get('/test')
  login(data: Context) {
    return 'Hello Word!'
  }
}

依赖注入

import { Controller, Get} from 'mango-core'
import type { Context } from 'mango-types'
@Controller({
  name: '测试模块',
  prefix: '/test',
  detail: {
    description: '这是一段测试模块的备注',
    tags: ['测试'],
  },
})
export default class DemoController {

  @Get()
  test(store: Context) {
    
  }
}

路由

Mango 提供了一个简单的路由系统,以下是一些常用的路由示例:

支持Get, Post, Put, Delete, All, Option, Patch, Custom请求

其中被All装饰会命中所有的请求

Custom装饰器则是自定义请求方法

import { Controller, Get, Post, Put, Delete, All, Option, Patch, Custom} from 'mango-core'
import type { Context } from 'mango-types'
@Controller({
  name: '测试模块',
  prefix: '/test',
  detail: {
    description: '这是一段测试模块的备注',
    tags: ['测试'],
  },
})
export default class DemoController {
  @Get('/test')
  test1(data: Context) {
    return 'Hello Word!'
  }

  @Post('/test')
  test2(data: Context) {
    return 'Hello Word!'
  } 
}

定时任务

基于@elysiajs/cron封装

import { Controller, Get, Cron} from 'mango-core'
import type { Context } from 'mango-types'
@Controller({
  name: '测试模块',
  prefix: '/test',
  detail: {
    description: '这是一段测试模块的备注',
    tags: ['测试'],
  },
})
export default class DemoController {
  @Cron({
    name: 'task1',
    pattern: '*/20 * * * * *',
  })
  cronTask() {
    console.log('任务1')
  }

  @Get('/stop/task')
  stopTask({ stopCronTask }: Context) {
    stopCronTask('task1')
    return '停止任务1'
  }
}

WebSocket

import { Controller, WebSocket} from 'mango-core'
import type { WebSocketContext } from 'mango-types'
@Controller({
  name: '测试模块',
  prefix: '/test',
  detail: {
    description: '这是一段测试模块的备注',
    tags: ['测试'],
  },
})
export default class DemoController {
  @WebSocket('/ws', {
    body: t.Object({
      name: t.String(),
      age: t.Number(),
    }),
  })
  websocket(ws: WebSocketContext, message: any) {
    ws.send(message)
  }
}

自定义装饰器

注意,自定义装饰器必须在请求装饰器下面

import { Controller, Get, Post, Put, Delete, All, Option, Patch, Custom} from 'mango-core'
import type { Context } from 'mango-types'
import { createParameterDecorator, HttpStatus, JsonResponse } from 'mango-core'

const test = createParameterDecorator<{
  body: any
}>((context) => {
  if (!context.body.name) {
    return JsonResponse(
      {
        code: HttpStatus.BAD_REQUEST,
        msg: '缺少名字',
      },
      HttpStatus.BAD_REQUEST,
    )
  }
  return true
})

@Controller({
  name: '测试模块',
  prefix: '/test',
  detail: {
    description: '这是一段测试模块的备注',
    tags: ['测试'],
  },
})
export default class DemoController {
  @Post('/test')
  @test
  test1(data: Context) {
    return 'Hello Word!'
  }
}

贡献

欢迎贡献

许可证

该项目采用 MIT 许可证