1.1.0 • Published 10 years ago

composey v1.1.0

Weekly downloads
3
License
MIT
Repository
github
Last release
10 years ago

composey npm version MIT license

Simple route module loading for Express with dependency injection

Install

npm install composey --save

Usage

Compose the route modules

var express = require('express');
var compose = require('composey');

var app = express();

compose({
  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) {
  	res.send('done');
  });
  
  return router;
};

API

compose(options

  • 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
1.1.0

10 years ago

1.0.0

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago