
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
express-router-controller
Advanced tools
Create routes from clases on es6 or es5. See specific examples for each enviorement (es5, es6-require, es6-import).
Create a config file (express-controllers.config.js) on root of your project:
import HomeController from './HomeController';
export default {
controllers: [
HomeController
],
defaultHome: 'Home',
defaultCommonName: 'Controller',
defaultRoute: 'index'
}
Register controllers to the router:
import express from 'express';
import expressRouterControllers from 'express-router-controller';
const router = express.Router();
expressRouterControllers.register(router);
// tun app
app.use(router);
app.listen(9000);
Create a static controller class to route your project:
route /
import { AbstractController } from 'express-router-controller';
class HomeController extends AbstractController{
constructor(){
super([
'get', 'post' // verbs
]);
}
index(req, res){
res.send('Hello world!');
}
}
Create a dinamic routes mapping to some method, the register do not load this method as static route ;) : /ID2232/foo route
import { AbstractController } from 'express-router-controller';
class HomeController extends AbstractController{
constructor(){
super([
'get', 'post' // verbs
]);
this.dinamic = {
'/:foo/bar':{
get: this.index.bind(this);
}
}
}
index(req, res){
res.send(`Hello world!, your id: ${req.params.id}`);
}
}
Example:
var util = require('util');
var AbstractController = require('express-controllers').AbstractController;
function ExampleController(){
AbstractController.call(this, ['get']);
}
util.inherits(ExampleController, AbstractController);
ExampleController.prototype.index = function(req, res){
res.send('Hello world');
}
module.exports = ExampleController;
For testing, only require and execute a instance of your controller:
With mocha + chai:
const HomeController = require('./HomeController');
const home = new HomeController();
const { expect } = require('chai');
describe('Testing home', () => {
it('should index response "Hello world!"', () => {
let value = 'foo';
const mockRequest = {
send: () => {
value = 'bar';
}
};
home.index(mockRequest);
expect(value).to.be.equals('bar');
});
});
FAQs
Controller for express router
We found that express-router-controller demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.