express-class-router
v1.0.4
Published
A class based router extension for ExpressJS written in ES6
Downloads
3
Readme
Class based routing for ExpressJS
ClassBasedRouter is a simple utility for building expressJS 4.x routers using ES6 classes.
Inspired from http://mkla.bz/2016/04/20/es6-class-express-routing.html
const ClassBasedRouter = require('class-based-router');
const express = require('express');
class SampleRouter extends ClassBasedRouter {
get middlewares(){
return [
['GET', '/*', 'exampleMiddleware']
]
}
get routes(){
return [
['GET', '/ping', 'ping']
]
}
exampleMiddleware(req, res, next){
console.log('middleware triggered!');
next();
}
ping(req, res){
res.json('pong')
}
}
let sample = new SampleRouter();
let app = express();
app.use('/', sample.router);
app.listen(3199, () => console.log('server started'));
Installation
Yarn
yarn add express-class-router
Npm
npm install --save express-class-router