3.1.0 • Published 9 years ago

express-common-controller v3.1.0

Weekly downloads
1
License
MIT
Repository
github
Last release
9 years ago

Express Common Controller

This is a common controller for using express

Current Status:

NPM Version NPM Downloads Build Status

NPM

Installation

$ npm|yarn install express-common-controller

Usage

First step:

Create a controller inherit BaseController.

  • HelloController.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

import { BaseController } from 'express-common-controller';

class HelloController extends BaseController {
  constructor() {
    super();
  }

  index() {
    this.render('Hello World');
  }
}

export default HelloController;

Second step:

Create a router config like this:

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

Third step:

Using routes config in server.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;
  }
});

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.

3.1.0

9 years ago

3.0.0

10 years ago

2.1.1

10 years ago

2.1.0

10 years ago

2.0.0

10 years ago

1.1.0

10 years ago

1.0.2

10 years ago

0.2.0

10 years ago

0.1.0

10 years ago