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

mini-koa

v1.0.0

Published

mini-koa是一个精简版koa和koa-router的结合,是一个值得学习Node网络框架封装的项目。

Readme

mini-koa

mini-koa是一个精简版koakoa-router的结合,是一个值得学习Node网络框架封装的项目。

这个项目是我根据日常使用koakoa-router的经验写的,没有参考过它们两者的源码,项目仅供学习。

mini-koa代码很精简,核心代码不超过300行,源代码配有详细的注释。

安装

NPM

npm i mini-koa -S

下载文件

可以直接下载项目到本地。

cd 项目目录

// 测试服务
npm run example

用法

用法跟koa类似,目前mini-koa支持以下方法:

Koa.prototype.use()
Koa.prototype.all()
Koa.prototype.get()
Koa.prototype.post()
Koa.prototype.listen()
Koa.prototype.addRoutes() # 添加子路由

// put/delete等其他方法类似get/post,故不加入源代码中

mini-koa-router支持以下方法:

Koa.prototype.use()
Koa.prototype.all()
Koa.prototype.get()
Koa.prototype.post()

其中,use/all/get/post等方法的url参数支持params写法,即

app.get('/user/:id')

在路由监听函数内,可以用的变量:

ctx.query: 查询参数('/user/abc?a=1')
ctx.params: 路由上的占位变量('/user/:id')

具体示例

// 代码放置在examples/server.js

const { Koa, KoaRouter } = require('mini-koa')
const app = new Koa()
// 路由用法
const userRouter = new KoaRouter({
  prefix: '/user'
})

// 中间件函数
app.use(async (ctx, next) => {
  console.log(`请求url, 请求method: `, ctx.req.url, ctx.req.method)
  await next()
})

// 方法示例
app.get('/get', async ctx => {
  ctx.body = 'hello ,app get'
})

app.post('/post', async ctx => {
  ctx.body = 'hello ,app post'
})

app.all('/all', async ctx => {
  ctx.body = 'hello ,/all 支持所有方法'
})

// 子路由使用示例
userRouter.post('/login', async ctx => {
  ctx.body = 'user login success'
})

userRouter.get('/logout', async ctx => {
  ctx.body = 'user logout success'
})

userRouter.get('/:id', async ctx => {
  ctx.body = '用户id: ' + ctx.params.id
})

// 添加路由
app.addRoutes(userRouter)

// 监听端口
app.listen(3000, () => {
  console.log('> App is listening at port 3000...')
})

联系作者

作者: Mask

项目地址: mini-koa