express-annotation

0.3.0 • Public • Published

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

Annotations / Decorators API

Licence

MIT © Thomas Sileghem

/express-annotation/

    Package Sidebar

    Install

    npm i express-annotation

    Weekly Downloads

    10

    Version

    0.3.0

    License

    MIT

    Last publish

    Collaborators

    • mastilver