node package manager
Orgs are free. Discover, share, and reuse code in your team. Create a free org »

express-highway

express-highway

Build Status

Extends express router with some goodies such as namespacing, resources and better middleware handling.

Installation

Install with npm:

npm install --save express-highway

Example

app.js

var express = require('express');
var app = express();
var highway = require('express-highway')(app);
 
// Require your routes file and call it in highway's context
var routes = require('./routes');
routes.call(highway);
 
app.listen(3000);
 

routes.js

module.exports = function() {
 
  this.get('/', HomeController, 'index');
 
  this.namespace('/api', function() {
 
    this.get('/', 'ApiController', 'home');
 
    this.namespace('/v1', function() {
 
      this.resource('/user', UserV1Controller);
 
    });
 
    this.namespace('/v2', function() {
 
      this.resource('/user', UserV2Controller, customBlueprint);
 
    });
 
  });
 
};

Resource

RESTful resources follow a default blueprint defined in lib/resource.js. You can easily override this by passing a custom blueprint as the third argument to this.resource().

NOTICE: Routes in controller that don't adhere to the blueprint will be IGNORED;

Testing

From the repo root:

npm install
npm test