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

route-dir

v0.3.1

Published

Recursively map directory structure to URIs

Readme

Recursively map directory structure to URIs

route-dir provides functionality to recursively map a directory structure to HTTP server URI supporting basic DSL syntax (in form of :id) in path names. The module was designed and tested with express, but does not have it as a dependency and will work in the same manner with other frameworks that use app.get, app.post etc. to register dispatch patterns. The module does not require that all routing patterns are registered in this manner and can be used in addition to any routing defined by other means.

Installation

$ npm install route-dir

Tests:

$ npm test

Usage

The code to handle requests needs to be arranged in a directory structure (e.g. server/routes) following these rules:

  • server/routes/index.js will map to /
  • server/routes/path/user/index.js will map to /path/user/
  • server/routes/path/user.js will map to /path/user (different from above)
  • server/routes/_colon_lang/user/_colon_id will map to /:lang/user/:id
  • server/routes/_star_ will map to /* as the last entry in the rule set

Request handlers are defined as functions get, post etc. exported by a module under server/routes:

exports.get = function(conn, config) {
    return function(req, res) {
        res.render("user/signup");
    };
};

exports.post = function(conn, config) {
    // 'conn' and 'server' can be used here e.g. to load a data model 
    // given a specific connection and using specific configuration
    return function(req, res, next) {
        var User = require("usermodel").getModel(conn);
        User.registerNewUser(req.body, function(err, user) {
            if (err) {
                next(err);
            } else {
                res.send(200, { userId: user.id });
                res.end();
            }
        });
    };
};

Here conn and config are optional arguments intended to pass a specific DB-connection (e.g. mongoose connection for connection-specific models as in the above example) and server configuration that may be needed in handling the request. Each exported function is expected to return a standard handler taking req, res or req, res, next arguments. These will be directly registered with the server:

...
var routing = require("route-dir");
var server = express();
...
server.use(server.router);
// register routes without passing connection or config to the handlers
routing.route(server, "server/routes");
// register routes passing in a specific connection and a config
// ensure the locations are not clashing with the above...
routing.route(server, "server/more-routes", mongoose.createConnection(config.db), config);

Using the module as an express middleware is currently under development and will be added shortly:

server.use(routing.route("server/routes"));

License

The MIT License

Copyright (c) 2014 Oleg Sklyar <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.