Router

new Router(name)

Router class

Parameters:
NameTypeDescription
namestring

Name of the Router

Since
  • 1.0.0
Author
  • Glenn de Haan
Example
const {Router} = require('@neobeach/core');
const IndexController = require('./IndexController');

const router = new Router('Api');
router.add('/api', IndexController);

module.exports = router;

Members

name :string

Router name used for internal logs

Type:
  • string
Since
  • 1.0.0
Author
  • Glenn de Haan

routes :array.<object>

Array of routes which to implement within Express

Type:
  • array.<object>
Since
  • 1.0.0
Author
  • Glenn de Haan

Methods

add(path, controller, middlewaresopt)

Binds a controller to a path within an Express Router

Parameters:
NameTypeAttributesDescription
pathstring

A path to bind the controller to

controller*

A Controller class reference

middlewaresarray.<function(*, *, *)><optional>

An array of middleware functions

Since
  • 1.0.0
Author
  • Glenn de Haan
Example
const {Router} = require('@neobeach/core');
const IndexController = require('./IndexController');

const router = new Router('Api');
router.add('/api', IndexController);

module.exports = router;