Skip to content

Latest commit

 

History

History
76 lines (42 loc) · 1.5 KB

README.md

File metadata and controls

76 lines (42 loc) · 1.5 KB

express-annotation Build Status Coverage Status

Bring annotation routing to expressJs

Install

$ npm install --save express-annotation

Usage

given a file /controllers/user.js:


// @route('/users')
module.exports.getAll = function(req, res){

};

// @route('/users/:id')
module.exports.get = function(req, res){
    console.log(req.params.id);
};

// @httpPut()
// @route('/users/:id')
module.exports.update = function(req, res){

};

you can register those routes by writing so:


var expressAnnotation = require('express-annotation');
var app = require('express')();

expressAnnotation(app, 'controllers/**/*.js', function(err){

    // routes have been added to the express instance

    app.listen(3030);
});

API

expressAnnotation(expressInstance, paths, callback)

expressInstance

required

express instance (value returned by: express())

paths

required
Type: array, string

callback(err)

Type: Function

will be called when all the routes have been added to the express instance

Licence

MIT © Thomas Sileghem