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

@routegraph/koa

v1.0.1

Published

Koa v2 adapter for RouteGraph.

Readme

@routegraph/koa

Koa adapter for RouteGraph — built on @koa/router.

Installation

pnpm add @routegraph/koa @routegraph/core koa @koa/router koa-body zod

koa (>=2.0.0) and @koa/router (>=12.0.0) are peer dependencies. koa-body is not a dependency of this package at all — it's your choice of body parser; see why below.

createKoaRouter(graph)

function createKoaRouter(graph: RouteGraph): Router   // @koa/router's Router

Usage

import Koa from 'koa'
import { koaBody } from 'koa-body'
import { RouteGraph } from '@routegraph/core'
import { createKoaRouter } from '@routegraph/koa'

const graph = new RouteGraph({ routesDir: './routes' })
await graph.load()

const app = new Koa()

app.use(koaBody())   // must come before the router — see below

const router = createKoaRouter(graph)
router.prefix('/api')
app.use(router.routes())
app.use(router.allowedMethods())

app.listen(3000)

Why koa-body must be applied before RouteGraph

Koa itself ships with no body parsing built in — ctx.request.body simply doesn't exist until something populates it. The adapter reads it structurally (getRequestBody() narrows unknown rather than importing koa-body's types, since this package doesn't depend on any specific body parser — see DECISIONS.md), so whichever body parser you choose (koa-body is what this monorepo's own example uses) must run before createKoaRouter(graph)'s router in the middleware chain, or every route with a body schema will see undefined and fail validation.

Usage with router.routes() + router.allowedMethods()

Both are required, in that order, for @koa/router to behave correctly — router.routes() dispatches matched requests, router.allowedMethods() handles 405/501 responses for methods RouteGraph didn't register at a matched path. This is standard @koa/router usage, not something RouteGraph changes.

Accessing the raw Koa context

const handler: RouteHandler<typeof config> = async (req, res) => {
  const ctx = req.raw as import('koa').Context
  console.log(ctx.ip)
}

Validation error format

{ "error": "Validation failed", "issues": [{ "field": "params.id", "message": "Invalid uuid", "code": "invalid_string" }] }

Hot reload

Routes are looked up fresh per request (graph.getRoute(method, urlPath)), so @routegraph/watcher's graph.reload() is reflected immediately without re-registering anything with @koa/router.