express-annotation

Bring annotation routing to express

Usage no npm install needed!

<script type="module">
  import expressAnnotation from 'https://cdn.skypack.dev/express-annotation';
</script>

README

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