Skip to content

Repository files navigation

Express Common Controller

This is a common controller for using express

Current Status:

NPM VersionNPM DownloadsBuild Status

NPM

Installation

$ npm|yarn install express-common-controller

Usage

First step:

Create a controller inherit BaseController.

  • HelloController.js
constBaseController=require('express-common-controller').BaseController;functionHelloController(){}HelloController.prototype=newBaseController();HelloController.prototype.index=function(){this.render("Hello World");};module.exports=HelloController;

Or Using ES6 style

import{BaseController}from'express-common-controller';classHelloControllerextendsBaseController{constructor(){super();}index(){this.render('Hello World');}}exportdefaultHelloController;

Second step:

Create a router config like this:

constpath=require('path');constExpressCommonControllerRouter=require('express-common-controller').default;constrouter=newExpressCommonControllerRouter();router.path=path.join(__dirname,'./js/controllers');router.get('/hello','HelloController#hello');module.exports=router.routes();

NOTEExpressCommonControllerRouter based on ExpressCommonRouter. More info please refer to here:express-common-router

Third step:

Using routes config in server.js

constexpress=require('express');constroutes=require('./routes');constapp=express();app.use(routes);app.listen(3000,'0.0.0.0',(err)=>{if(err){console.log(err);return;}});

Config your routes.

This component support all methods which supported by express.

About the details of config route, please refer to here: Express Router

License

express-common-controller is released under the MIT license.

About

Common base controller implemented by express

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages