A problem of ExpressJS

routing

class BaseController {

    constructor(req, res, next) {

        console.log("-------------", req);

        this.req  = req;
        this.res  = res;
        this.next = next;
        this.data = req.body || req.query; // 
    }
}
module.exports = BaseController();

how can the parameters such as req routed by everyone be passed into the controller and new Login (req, res, next) when the module is imported?

Thank you

Mar.04,2021

routing

router.post('/login', (req, res, next) => {
    require('../app/controller/admin/login')(req, res, next).login
});

Controller output function

let BaseController = require('../BaseController');
class Login extends BaseController {
    // 
    login() {
        console.log(this.req); // undefiend
    }
}
// here here here here here here
module.exports = (req, res, next) => {
    return new Login(req, res, next)
};

Base class output should not be parenthesized

class BaseController {
    constructor(req, res, next) {
        console.log('-------------', req);
        this.req  = req;
        this.res  = res;
        this.next = next;
        this.data = req.body || req.query; // 
    }
}
module.exports = BaseController;

  1. the code in the controller has syntax errors
  2. class keyword usage error in
  3. base class
Menu