如何从node.js获取IP地址我尝试了很多方法,但它不起作用并返回:: ffff:127.0.0.1请给我一些建议如何获取node.js中的IP地址
这是我的代码:
app.put('/update-user-info', function(req, res){
// it's doesn't work and return ::ffff:127.0.0.1
var ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress || req.socket.remoteAddress || req.connection.socket.remoteAddress;
});
使用'req.ip'。如果你在一个proxi后面看看:http://expressjs.com/en/guide/behind-proxies.html –