Modifying Express.js Request Object

You can add a custom middleware that sets the property for each request:

app.use(function (req, res, next) {
    req.root = req.protocol + '://' + req.get('host') + "https://stackoverflow.com/";
    next();
});

Using req.get to obtain the Host header, which should include the port if it was needed.

Just be sure to add it before:

app.use(app.router);

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)