Common base controller implemented by express
npm install express-common-controllerThis is a common controller for using express
Current Status:




```
$ npm|yarn install express-common-controller
Create a controller inherit BaseController.
* HelloController.js
`js
const BaseController = require('express-common-controller').BaseController;
function HelloController() {}
HelloController.prototype = new BaseController();
HelloController.prototype.index = function() {
this.render("Hello World");
};
module.exports = HelloController;
`
Or Using ES6 style
`js
import { BaseController } from 'express-common-controller';
class HelloController extends BaseController {
constructor() {
super();
}
index() {
this.render('Hello World');
}
}
export default HelloController;
`
Create a router config like this:
`js
const path = require('path');
const ExpressCommonControllerRouter = require('express-common-controller').default;
const router = new ExpressCommonControllerRouter();
router.path = path.join(__dirname, './js/controllers');
router.get('/hello', 'HelloController#hello');
module.exports = router.routes();
`
NOTE ExpressCommonControllerRouter based on ExpressCommonRouter.
More info please refer to here:express-common-router
Using routes config in server.js
`js
const express = require('express');
const routes = require('./routes');
const app = express();
app.use(routes);
app.listen(3000, '0.0.0.0', (err) => {
if (err) {
console.log(err);
return;
}
});
`
This component support all methods which supported by express`.
About the details of config route, please refer to here: Express Router
express-common-controller is released under the MIT license.