node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »


composey npm version MIT license

Simple route module loading for Express with dependency injection


npm install composey --save


Compose the route modules

var express = require('express');
var compose = require('composey');
var app = express();
  app: app,
  routes: {
    './lib/some-module': {
      imports: {
        anotherModule: require('another-module'),
        myModule: require('my-module')
app.listen(3000, function () {
  console.log('server started');

Example module ./lib/some-module

module.exports = function (imports) {
  var router = imports.Router();
  var anotherModule = imports.anotherModule;
  var myModule = imports.myModule;
  router.get('/testing', function (req, res) {
  return router;



  • options
    • app - Express app object. If you don't provide an app object, it creates one for you.
    • imports - Default imports to pass to all routes
    • root - the root directory to prepend to the path of the modules. Defaults to relative to calling file __dirname
    • routes - a key/value map of route modules to load. The key is the path to the route module, and the value is another key/value map stating which modules to inject.
    • mount - the path the mount the route at. Defaults to /

Run Tests

npm install
npm test