randomuser1
randomuser1

Reputation: 2803

How can I get the correct ip address of the visitor in node.js? (I tried node-ip and it doesn't work)

I'm using a node ip taken from here: https://github.com/indutny/node-ip

In my webservice I did a simple thing:

var ip              = require('ip');

module.exports = function(app) {

app.get('/gps', function (req, res) {

    console.log(ip.address());
}
}

I deployed it to my amazon aws account and now whoever enters the page - I constantly see the same ip address in my console log - 172.31.46.96. I tried to check what is this ip (possible option is that it is related to my amazon aws service?), but who.is does not bring the answer.

How should I change my code to see every visitor's ip address instead?

Upvotes: 0

Views: 244

Answers (2)

Yuri Zarubin
Yuri Zarubin

Reputation: 11677

Use req.connection.remoteAddress to get the ip of your user.

Upvotes: 0

Gabriel Isenberg
Gabriel Isenberg

Reputation: 26341

You're most likely getting an IP of an internal load balancer/proxy and you'll need to configure express to handle that.

This is a good place to start.

Upvotes: 1

Related Questions