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

express-route-builder

v0.0.13

Published

Quickly compile Express.js routes with minimal code.

Readme

Express-Route-Builder

Quickly compile Express.js routes with minimal code.

NOTE: Requires Node.js v6.x

Quick Use

The following example will help you get up and running quickly but you can also take a look at the API reference further down which contains more options.

index.js

Setup your Express app as usual. It's a good idea to create a separate module to handle the building of your routes so as to keep your index.js minimal.

const express = require('express');
const app = express();
const routes = require('./routes');

routes.setup(app);

routes.js

Specify the module filenames that will handle each path with the .addRoute() method.

const path = require('path');
const express = require('express');
const ExpressRouteBuilder = require('express-route-builder');

module.exports.setup = function (app) {
  const baseDir = path.join(__dirname, 'controllers/');
  const builder = new ExpressRouteBuilder(express, app, baseDir);

  // You can specify the name of the controller files for each path.
  builder.addRoute('/comments', 'comments');
  builder.addRoute('/users', 'users');

  // Or you can explicitly define functions for each route and method.
  builder.addRoute('/other/data', {
    get: (req, res, next) => { ... },
    post: (req, res, next) => { ... },
    ...
  })
};

controllers/comments.js (etc)

In each of the route modules you should specify functions named after the HTTP methods you want to expose. You can use any of the HTTP methods that Express supports, including:

get, post, put, head, delete, options, trace, copy, lock, mkcol, move, purge, propfind, proppatch, unlock, report, mkactivity, checkout, merge, m-search, notify, subscribe, unsubscribe, patch, search, connect

Note: The function names must be lowercase.

module.exports.get = function (req, res, next) { ... };
module.exports.post = function (req, res, next) { ... };
// ...and so on.

Static Files

Serving up static files is very easy and uses the same arguments as express.static() except with the arguments reversed. To specify multiple static directories call the .addStatic() method multiple times. Files will be looked up in the order the directories are specified.

  // Adds a directory from which express will serve up your static files.
  // For "photo.jpg" the resulting URL will be "http://www.example.com/photo.jpg"
  // and the file will be served up from the directory specified.
  builder.addStatic('/path/to/static/directory');

  // You can also specify a prefix to use in the URL as the second parameter.
  // This time "photo.jpg" will have a URL of "http://www.example.com/images/photos/photo.jpg"
  builder.addStatic('/path/to/static/directory', 'images/photos');

API

new ExpressRouteBuilder(express, app, baseDir = process.cwd());

Creates a new instance of the builder. The base directory is optional and defaults to the current working directory of your app.

.addRoute(path, input, middleware = []);

Adds a route to your Express app based on the path given; you can specify any path that Express accepts. The input parameter should be either a filename of the module which will handle this route (relative to the base directory given in the constructor) or an object containing functions with keys based on the HTTP methods supported by express. Also, you can optionally specify an array of middleware functions to use before the route is processed.

.addStatic(dir, prefix = null, middleware = [], options = {});

Adds a directory to your express app where static files will be served up from. The directory will be relative to the current working directory of your app so it's a good idea to specify an absolute path. The prefix parameter is optional and will be prepended to the file path in the URL, just like with express.static(). Also, you can optionally specify an array of middleware functions to use before any files in the static directory are served up. The options parameter is the same as express.static().