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

hono-mas

v0.0.5

Published

Auto route loader for Hono framework – load routes from filesystem with optional middleware support and hot reload (in dev mode).

Readme

hono-mas

Auto route loader for Hono framework – load routes from filesystem with optional middleware support and hot reload (in dev mode).

🔧 Installation

bun add hono-mas

or

npm install hono-mas

🚀 Usage

This package allows you to auto-load API routes from a folder (default: ./api) and mount them to your Hono app.

⚠️ You must create at least:

  • an index.js file (to initialize the app and call loadRoutes)
  • a route.ts file (inside your api folder) to define at least one route

Minimal Setup

index.js

import { Hono } from "hono";
import { loadRoutes } from "hono-mas";

const app = new Hono();

const server = async () => {
  await loadRoutes(app); // Loads all routes from ./api

  console.log("🚀 Server running on http://localhost:3000");

  Bun.serve({
    fetch: app.fetch,
    port: 3000,
  });
};

server();

api/route.ts

export const GET = (c) => {
  return c.text("Hello from root route!");
};

📁 File Structure

Example directory structure for auto-loading:

api/
├── route.ts                 // Handles GET, POST, etc. for `/api`
├── parentMiddleware.ts      // Middleware applied to this folder and children
└── users/
    ├── route.ts             // Will be mounted at /api/users
    └── parentMiddleware.ts

✅ Features

  • ✅ Recursive route loading
  • ✅ Folder-based middleware (parentMiddleware.ts)
  • ✅ Supports per-method middleware (GET_middleware.ts, POST_middleware.ts, etc.)
  • ✅ Supports hot reload in dev mode (using watch)

🧱 Middleware Usage Guide

Folder-level middleware

To apply middleware to a folder and its children, create a file named parentMiddleware.ts in that folder:

import { MiddlewareHandler } from "hono";

const middleware: MiddlewareHandler = async (c, next) => {
  console.log("Folder-level middleware executed");
  await next();
};

export default middleware;

Method-specific middleware

To apply middleware for a specific HTTP method, create files like GET_middleware.ts, POST_middleware.ts, etc.:

import { MiddlewareHandler } from "hono";

const GET_middleware: MiddlewareHandler = async (c, next) => {
  console.log("GET middleware triggered");
  await next();
};

export default GET_middleware;

🛠 Custom Options

You can customize the behavior of route loading:

await loadRoutes(app, "./my-folder", "/custom-path", [yourMiddleware], true);
  • ./my-folder – source directory for route files
  • /custom-path – base route path
  • [yourMiddleware] – global middleware applied to all routes
  • true – enable hot reload

🧪 Validation Helper

Also includes a helper for Zod schema validation:

import { Schema } from "hono-mas";
import { z } from "zod";

const schema = z.object({
  name: z.string(),
});

app.post("/example", async (c) => {
  const body = await c.req.json();
  return Schema(body, schema, c);
});

📝 License

MIT