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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@axel669/hono-file-routes

v1.0.1

Published

A small library for adding file-based routing into hono routes at bundle time using rollup. The goal was to bring file-based routing to places like Cloudflare Workers and AWS Lambda with a simple, consistent interface.

Readme

Hono File Routes

A small library for adding file-based routing into hono routes at bundle time using rollup. The goal was to bring file-based routing to places like Cloudflare Workers and AWS Lambda with a simple, consistent interface.

Installation

Available in the standard package managers

pnpm add @axel669/hono-file-routes

Usage

  1. Configure the plugin with rollup
  2. Create the routes directory with the desired routes
  3. Import the route directory into your code

The examples directory of the repo contains a NodeJS and a Cloudflare Workers example that can be run, and a Bruno collection for each of the routes.

Importing in Code

Importing with the file-routes@ prefix on the directory to import will have the plugin create a hono router from the routes in the directory. Normal import resolution rules apply to the location (relative vs absolute file paths).

import router from "file-routes@./routes"

Rollup Config

import fileRoutes from "@axel669/hono-file-routes"

export default {
    input: "main.js",
    output: {
        file: "your-output-file",
        format: "esm"
    },
    plugins: [
        fileRoutes({
            debug: true
        })
    ]
}

If debug is true the library will console.log information on what routes are being imported and setup when the script begins.

File Routes

There are 4 route types that can be defined by the files and their locations. An example of the order these run is provided after all the descriptions.

In order for a file to register a route action, it needs to export variables named $<method> and / or $any. Specific methods will always match before $any handlers (ex: if $get matches, $any in the same file won't).

The exported value for any handlers should be either a function, or an array of functions that are used as Hono routing functions. If the exported value is an array, all the handlers are added for the same route/verb in the order they appear in the array. Additionally, if any of them in the list returns it will make the route return and not go to subsequent handlers, just like middleware in Hono.

The library doesn't modify how any of the Hono context functions work, it just makes it easier to setup routes based on file paths, so all context functions are available as-is per the Hono docs.

Middleware

Middleware Routes are files named _middleware.js in a folder. Middleware runs before any routes in a folder, in a top down fashion (examples later).

Wildcard Routes

Wildcard routes match any route not defined in a directory and are defined by naming a file as [[<name>]].js.

Parameter Routes

Parameter routes are routes that have parameters in them and are defined by naming a file or folder as [<param name>]. Any valid part of a path can match against a parameter, and more than one parameter can exist on a route.

Static routes

Any route that isn't formatted as one of the previous types will be treated as a static route. The files and directories don't have any special syntax required (other than being .js files).

Routing Example

routes/
├─ dir/
│  ├─ _middleware.js
│  ├─ static.js
│  ├─ [[nested-wildcard]].js
├─ user/
│  ├─ _middleware.js
│  ├─ logout.js
│  ├─ [userID].js
├─ [param1]/
│  ├─ [param2]/
│  │  ├─ thing.js
│  ├─ [file-param].js
├─ _middleware.js
├─ [[no-route]].js

This set of files will generate the following Hono routes:

/dir/static
/dir/*
/user/logout
/user/:userID
/:param1/:file-param
/:param1/:param2/thing
/*

Routes are added to Hono in such a way that the resolution order is always the same:

  1. static routes
  2. parameterized routes
  3. wildcards

Routing Resolution

Using the previous set of routes, this is what the execution will look like given some example requests.

/dir/static
-> run /_middleware.js
-> run /dir/_middleware.js
-> match /dir/static.js

/dir/random-thing
-> run /_middleware.js
-> run /dir/_middleware.js
-> match /dir/[[nested-wildcard]].js

/user/logout
-> run /_middleware.js
-> run /user/_middleware.js
-> match /user/logout.js

/user/id-123
-> run /_middleware.js
-> run /user/_middleware.js
-> match /user/[userID].js

/user/not/valid
-> run /_middleware.js
-> run /user/_middleware.js
-> match /[[no-route]].js

/first/second/thing
-> run /_middleware.js
-> match /[param1]/[param2]/thing.js

/first/second
-> run /_middleware.js
-> match /[param1]/[file-param].js