Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

express-base-class

Package Overview
Dependencies
Maintainers
5
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-base-class

Base ES6 class for ExpressJS controllers

  • 2.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
5
Created
Source

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

Keywords

FAQs

Package last updated on 23 Feb 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc