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-common-router

v2.2.1

Published

Common routes for express

Downloads

55

Readme

Express Common Router

This is a common router for express.

Current Status:

NPM version NPM version Build Status

NPM

Installation

$ npm|yarn install express-common-router

Usage

First step:

Create two handlers:

  • Hello.js
module.exports = function(req, res, next) {
  res.send("Hello World");
};
  • Test.js
exports.index = function(req, res) {
  res.send("Hello Index");
};
exports.show = function(req, res) {
  res.send("Hello Show");
}
  • NotFound.js
exports.index = function(req, res) {
  res.send("Not Found");
};

Second step:

Create a routes config.

  • routes.js
const path = require('path');
const ExpressCommonRouter = require('express-common-router').default;

const handlerPath = path.join(__dirname, './js/handlers')
const router = new ExpressCommonRouter(handlerPath);

router.use('/hello', 'Hello'); //Must use the same name with file name.
router.get('/test/index', 'Test#index'); //Handler name and action name separated by '#'
router.get('/test/index', 'Test#index'); //More method please refer to 'express'
router.all('*', 'NotFound'); //More method please refer to 'express'

module.exports = router.routes();

ES6 Style

import path from 'path';
import ExpressCommonRouter from 'express-common-router';

const router = new ExpressCommonRouter();
router.path = path.join(__dirname, './js/handlers');

router.use('/hello', 'Hello'); //Must use the same name with file name.
router.get('/test/index', 'Test#index'); //Handler name and action name separated by '#'
router.get('/test/index', 'Test#index'); //More method please refer to 'express'

module.exports = router.routes();

Third step:

Using routes in server.js

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

app.use(routes);

app.listen(3000, '0.0.0.0', (err) => {
  if (err) {
    console.log(err);
    return;
  }
});

More Details

How to set handler file path?

  • Passing path as a parameter when create an instance of ExpressCommonRouter.

const handlerPath = path.join(__dirname, './handlers');
const router = new ExpressCommonRouter(handlerPath);
  • Calling path method for ExpressCommonRouter instance.

const router = new ExpressCommonRouter();
router.path = path.join(__dirname, './handlers');

Set custom HandlerManager.

  • Create a custom HandlerManager like this:
class CustomHandlerManager {
  getHandlerAction(actionPath) {
    ...
  }
}
export default CustomHandlerManager;
  • Config CustomHandlerManager into router config file.
import ExpressCommonRouter from 'express-common-router';
import CustomHandlerManager from './CustomHandlerManager';

const router = new ExpressCommonRouter();
router.manager.actionManager = new CustomHandlerManager();

Set custom FileLoader.

  • Create a custom FileLoader like this:
class CustomFileLoader {
  loadFiles(handlerPath) {
    ...
  }
}
export default CustomFileLoader;
  • Config CustomFileLoader into router config file.
import ExpressCommonRouter from 'express-common-router';
import CustomFileLoader from './CustomFileLoader';

const router = new ExpressCommonRouter();
router.manager.fileLoader = new CustomFileLoader();

Set custom HandlerLoader.

  • Create a custom HandlerLoader like this:
class CustomHandlerLoader {
  loadHandler(handlerFile) {
    ...
  }
}
export default CustomHandlerLoader;
  • Config CustomHandlerLoader into router config file.
import ExpressCommonRouter from 'express-common-router';
import CustomHandlerLoader from './CustomHandlerLoader';

const router = new ExpressCommonRouter();
router.manager.handlerLoader = new CustomHandlerLoader();

Set custom ActionLoader.

  • Create a custom ActionLoader like this:
class CustomActionLoader {
  loadAction(handler, actionName) {
    ...
  }
}
export default CustomActionLoader;
  • Config CustomActionLoader into router config file.
import ExpressCommonRouter from 'express-common-router';
import CustomActionLoader from './CustomActionLoader';

const router = new ExpressCommonRouter();
router.manager.actionLoader = new CustomActionLoader();

Config your routes.

This component support all methods which supported by express.

About the details of config route, please refer to here: Express Router

License

express-common-router is released under the MIT license.