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

express-route-configuration

v0.1.4

Published

Express middleware to auto detect routes

Readme

express-route-configuration

This project is a utility module that allows you to write your route configuration and validation in the controller module itself. The modules are auto-detected and the routes created without having to manually set them.

Usage

Supports both ESM and CommonJS.

ESM

server.js

import express from 'express';
import routeConfig from 'express-route-configuration';
import path from 'path';
import { fileURLToPath } from 'url';

const dirname = path.dirname(fileURLToPath(import.meta.url));

const app = express();

routeConfig(app, path.join(dirname, 'routes'));

app.listen(3000);

routes/hello.js

import Joi from 'joi';

export default {
  helloWorld: {
    method: 'GET',
    path: '/hello/:name',
    config: {
      validate: {
        params: Joi.object({
          name: Joi.string().required(),
        }),
        query: Joi.object({
          age: Joi.number().min(0).max(100).optional(),
        }),
      },
      async handler(req, res) {
        if (req.query.age) {
          res.send(`Hello ${req.params.name}, age ${req.query.age}`);
        } else {
          res.send(`Hello ${req.params.name}, of unknown age`);
        }
      },
    },
  },
};

CommonJS

server.js

const express = require('express');
const routeConfig = require('express-route-configuration');
const path = require('path');

const app = express();

routeConfig(app, path.join(__dirname, 'routes'));

app.listen(3000);

routes/hello.js

const Joi = require('joi');

exports.hello = {
  path: '/hello',
  method: 'GET',
  config: {
    validate: {
      params: Joi.object({
        name: Joi.string().required(),
      }),
      query: Joi.object({
        age: Joi.number().min(0).max(100).optional(),
      }),
    },
    async handler(req, res) {
      res.send('Hello world');
    },
  },
};

The route is created automatically based on the discovery path. URL Parameters, query string and payload values are checked for their type and if matches the schema the handler is called.

Options:

routeConfig(app, path, options) task the following options:

  • app: The instance of Express
  • path: A path string where to search for routes
  • options: Additional optional configuration parameters

Additional optional config includes:

  • parsePayload: If true, use body-parser to convert payload body to object
  • ignore: An array of paths and files to ignore when search for controllers
  • validationErrorStatusCode: The HTTP Status Code to issue when validation fails, normally 422
  • debug: More verbose logging

Controllers:

The controller modules are fairly simple in their setup. Create an exported object with the following schema:

{
  method: String('GET', 'POST', 'UPDATE', 'PUT', 'PATCH', 'DELETE'),
  path: String(),
  config: {
    validate: {
      params: optional JoiObject(),
      query: optional JoiObject(),
      payload: optional JoiObject(),
    },
    handler: async function(req, res),
  },
}

The path string follows the express.js format using a colon to define a variable, /path/:variable.

Validation fields use Joi, documentation here.

Building

To build both the ESM and CommonJS distribution run the script npm run build.

TODO Add more details on exactly what happens

Issue

There is a problem with V8's support of dynamic imports and how jest works with in band testing. This means using dynamic imports can be hit or miss. As a unit test option the main entry point now can take a string path or the imported controller module. If your unit tests fail try converting to something along these lines.


import express from 'express';
import configRoutes from 'express-route-configuration'
import helloRoutes from '../../controller/hello.js'

test('testing routes', async () => {
  const app = express();
  configRoutes(app, helloRoutes { debug: true });

  // Normal test accessing routes
});