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

ex-router

v1.10.2

Published

A lightweight, automatic file-based routing, inspired by Next.js-style dynamic routes.

Readme

NPM Version Downloads License

alt text

ex-router

A lightweight and flexible file-based routing system for Express.js, Hono, Diesel, or any other framework.

🚀 Features

  • Simple and easy-to-use routing system
  • Automatic route loading from a directory
  • Works seamlessly with Express.js, Hono, Diesel
  • Supports defining multiple HTTP methods in a single route file

Note: Fastify requires a workaround using setTimeout (100-200ms) to prevent errors.

  • Wrap loadRoutes func under setTimeout and give time from 100ms or more until it works.
  • Or you can use fastify-autoload which is native fastify library

📦 Installation

Bun

bun install ex-router

NPM

npm install ex-router

🔥 Usage

Import loadRoutes and initialize it with your app:

import express from 'express';
import { loadRoutes } from 'ex-router';

const app = express();
const port = 3000;

// Load routes
loadRoutes(app, {
    routeDir: process.cwd() + '/src/routes',
    prefixUrl: ''
});

app.get('/', (_, res) => {
    res.send('Hello, world!');
});

app.listen(port, () => {
    console.log(`Server is running on port ${port}`);
});

📂 Folder Structure

Note: Ensure your server file is in the root directory and routes folder is under src/.

example/
├── src/
│   ├── controller/
│   ├── routes/
│   │   ├── auth/
│   │   │   ├── login.ts
│   │   │   ├── register.js
│   │   ├── user/
│   │   │   ├── profile/
│   │   │   │   ├── index.ts
│   │   │   │   ├── delete.ts
│   │   │   │   ├── videos.ts
│   ├── utils/
│   ├── server.ts // root

📝 API Reference

loadRoutes(app, options)

Parameters:

  • app - The application instance.
  • options.routeDir - The directory containing route files.
  • options.prefixUrl (optional) - A prefix for all routes.

🔗 Example API Endpoints

Without Prefix (prefixUrl: '')

File Path                          | API Route
------------------------------------|-----------
src/routes/hello.ts                | /hello  
src/routes/auth/login.ts           | /auth/login  
src/routes/user/profile/index.ts   | /user/profile  
src/routes/user/profile/videos.ts  | /user/profile/videos  

With Prefix (prefixUrl: '/api/v1')

loadRoutes(app, {
    routeDir: process.cwd() + '/src/routes',
    prefixUrl: '/api/v1'
});
File Path                          | API Route
------------------------------------|-----------
src/routes/hello.ts                | /api/v1/hello  
src/routes/auth/login.ts           | /api/v1/auth/login  
src/routes/user/index.ts           | /api/v1/user  
src/routes/videos/api.ts           | /api/v1/videos  
src/routes/user/videos.ts          | /api/v1/user/videos  

🛠 Routing Rules

  1. Folders act as route segments

    • Example: routes/user/profile.ts/user/profile
  2. index.ts or api.ts acts as the root

    • Example: routes/user/index.ts/user
    • Example: routes/user/api.ts/user
    • Example: routes/user/profile/index.ts/user/profile
    • Example: routes/user/profile/api.ts/user/profile
  3. Multiple HTTP Methods in a Single File

    • Users can define multiple HTTP methods (GET, POST, PUT, DELETE, etc.) within the same route file.

Example

  • src/routes/login.ts
export const GET = (req, res) => {
    return res.send("Hello from login GET request.");
};

export const POST = (req, res) => {
    const { username, password } = req.body;
    if (!username || !password) {
        return res.status(400).send("Username and password are required");
    }
    return res.send("Login successful");
};

💡 Why Use import?

This project is built with modern JavaScript standards. Use ES Modules (import statements) for better compatibility and maintainability.

⚡ Contributing

Contributions are welcome! Feel free to submit issues or pull requests.

📜 License

This project is licensed under the MIT License.