express-highway

Powered Express router with namespaces, resources and better middleware support.

npm install express-highway
4 downloads in the last week
4 downloads in the last month

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
npm loves you