2.2.0 • Published 3 years ago

express-base-class v2.2.0

Weekly downloads
53
License
MIT
Repository
github
Last release
3 years ago

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:

  1. Create a Controller
const BaseController = require('express-base-class');


class DefaultController extends BaseController {
  default(req, res) {
    // `this` is DefaultController instance - bound automatically
    res.status(404).send('Page doesn\'t exist');
  }
  attachRoutes() {
    this.get('*', this.default);
  }
}

module.exports = new DefaultController();
  1. Attach a Controller to an Express app
const defaultController = require(`./controllers/default`); // Returns a controller instance.
defaultController.use(app); // Attaches router to the app
2.2.0

3 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.0

5 years ago

1.0.0

6 years ago

0.0.1

7 years ago