express-base-class
Base controller class that allows you to easily attach route handlers that are automatically bound to the class instance. Each instance creates it's own router, which allows for better route composition/encapsulation.
Example:
const BaseController = require('express-base-class');
class DefaultController extends BaseController {
default(req, res) {
res.status(404).send('Page doesn\'t exist');
}
attachRoutes() {
this.get('*', this.default);
}
}
module.exports = new DefaultController();
- Attach a Controller to an Express app
const defaultController = require(`./controllers/default`);
defaultController.use(app);