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
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e467c7-4c2c3.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e467c7-4c2c3.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?