In express.js, I would like to provide an additional attribute on the request object for each of my URI listeners. This would provide the protocol, hostname, and port number
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') + '/';
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);