https://github.com/mastilver/express-annotation
Bring annotation routing to express
https://github.com/mastilver/express-annotation
Last synced: 12 months ago
JSON representation
Bring annotation routing to express
- Host: GitHub
- URL: https://github.com/mastilver/express-annotation
- Owner: mastilver
- License: mit
- Created: 2015-03-06T19:22:33.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2016-12-23T12:59:31.000Z (over 9 years ago)
- Last Synced: 2025-05-09T04:48:40.327Z (about 1 year ago)
- Language: JavaScript
- Size: 7.81 KB
- Stars: 25
- Watchers: 1
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# express-annotation [](https://travis-ci.org/mastilver/express-annotation) [](https://coveralls.io/r/mastilver/express-annotation?branch=master)
> Bring annotation routing to [expressJs](https://github.com/strongloop/express)
## 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](https://github.com/mastilver/node-annotation-router#annotations-api)
## Licence
MIT © Thomas Sileghem