I really think this should be easy. But when I render a jade template, I also want to grab the ip address. My code look like this.
app.js
app.get('/', index.home)
index.js
exports.home = function(req, res) {
res.render('index');
};
Where can I add something like:
var ip = req.header('x-forwarded-for') || req.connection.remoteAddress; //or
console.log(req.connection.remoteAddress);
Just use
req.ip
and make sure you haveapp.enable('trust proxy');
if your app is deployed behind a reverse proxy. Express has all the header parsing and proxy logic baked in for you.