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-tree

v4.6.0

Published

Make router freedom by your finger. Resetful routing for express with lightly and structured.

Readme

express-route-tree

Path is route.
This route can provided a very convenient and quickly way to create routes for the express application.

Let's see it.

Install

npm install express-route-tree

Features

  1. Auto route without a large configuration file.
  2. Restful mode. Every path may be a parameter, if you want.
  3. In index function and path not include 'index', the first 'xx.html' parameter will be parsed to 'xx' for SEO requirement.
  4. Support express 3.x and 4.x
  5. Alias where ever you want.

Update

  1. There will be not come to the default index function when route not find corresponding function, if the index function have not more than 3 arguments.[new in 4.1.0]
  2. Add alias feature. [new in 4.3.0]

Class

route(controllerDirectory[, alias][, unknowRouteHandler]

  • controllerDirectory is a string of controller directory.
  • alias is a object for alias to a path or function.
  • unknowRouteHandler is a function to handler the unknow route.

Usage

// File: app.js

var express = require('express'),
    app = express(),
    route = require('express-route-tree');

app.use(route(__dirname + '/controller'));
/*
// Advanced Settings
var fileRouter = ['robots.txt'],
    shortAddress = ['mon', 'tus'],
    regionRoute = { china: { id: '1', name: '中国' } };
app.use(route(__dirname + '/controller', {
    season: '/index/season', // GET /season === GET /index/season
    '/a/b': '/index/season'  // GET /a/b === GET /index/season
}, function(req, res, next, controller) {
    var pathname = req.path.substring(1);
    if (~fileRouter.indexOf(pathname)) {
        return res.sendFile(pathname, { maxAge: 3600 * 24 * 1000 });
    } else if (~shortAddress.indexOf(pathname))) {
        // some short address
        return controller.index.season(req, res, next, shortAddress[pathname] + 1);
    } else if (regionRoute[pathname]) {
        return controller.index.region(req, res, next, regionRoute[pathname].id, regionRoute[pathname].name);
    } else {
        return next('No such route.');
    }
});
*/

// Add alias: `{ season: 'index.season' }`, and
// GET /index/season/2 is equivalent to GET /season/2

// Add alias: `{ '/a/b': '/index/season' }`, and
// GET /index/season/2 is equivalent to GET /a/b/2

// try it:
// console.log(route.controller);
// File: controller/app/list.js

/**
 * Normal Get Request, Support urls:
 * 1. /app/list => page: undefined | second: undefind
 * 2. /app/list/0 => page: 0 | second: undefined
 * 3. /app/list/1.html => page: 1 | second: undefined
 * 4. /app/list/1/a => page: 1 | second: a
 */
exports.index = function(req, res, next, page, second) {
    res.send('Page: ' + page + ' Second: ' + second);
    res.end();
};

/**
 * @Caution:
 *  if you want to use index with other(not get) request method.
 *  you must use full path: /app/list/index/1/a
 *  otherwise, request will be transfered to index function.
 *  Also, if there is not matched function, such as '/app/test'(no `exports.test = function(){}` in app.js),
 *  Then, router will send this request to `app.index` function,
 *  And put the `test` as the four argument, like `function(req, res, next, test)`
 */

/**
 * For POST Request. Support urls:
 * 1. /app/list/set => page: undefined | second: undefind
 * 2. /app/list/set/0 => page: 0 | second: undefined
 * 3. /app/list/set/1 => page: 1 | second: undefined
 * 4. /app/list/set/1/a => page: 1 | second: a
 */
exports.postSet = function(req, res, next, page, second) {
    res.send('Page: ' + page + ' Second: ' + second);
    res.end();
}

/**
 * For PUT Request. Support urls:
 * 1. /app/list/setapp => page: undefined | second: undefind
 * 2. /app/list/setapp/0 => page: 0 | second: undefined
 * 3. /app/list/setapp/1 => page: 1 | second: undefined
 * 4. /app/list/setapp/1/a => page: 1 | second: a
 */
exports.putSetapp = function(req, res, next, page, second) {
    res.send('Page: ' + page + ' Second: ' + second);
    res.end();
}

// And also support any method from request header.
// like: exports.deleteApp = function(req, res, next, ...) { ... }

Test

mocha
# or
npm test # npm run-script test

The End

Anyway, try to use. And see the example in test directory.

Hope this is useful to you.

And give me your pull request if you have any improvements or suggestions.