I will assume the Op is using this API - http://geo.ipify.org/api/v2/country
The API is actually working well both locally and in production (on Heroku). The real issue or the reason why the Heroku server's IP address is showing instead of the visitor's IP address is that you are now calling the API from the Heroku server as mentioned by @SuperStormer.
As the Op pointed out, there are different ways to obtain a user's Ip address in express.js.
I ran a check on using these three both locally and on Heroku
- req.ip
- req.headers.["x-forwarded-for"]
- req.connection.remoteAddress
Here is what it looks like on Heroku logs

PS: Trust proxy has been set to true which is why req.ip
has the same value as req.headers.["x-forwarded-for"]
.
The IP address returned by req.connection.remoteAddress
is an IPv4 address expressed in IPv6 notation and since it does not conform with the previous values it attests to the fact that there exists a proxy between the client and the server.
When you are on localhost: the IP address usually returned from accessing the req object is ::1
.
::1
is actually an IP Address and is IPV6 notation for localhost. The loopback address in IPv4 is 127.0.01. In IPv6, the loopback address is 0:0:0:0:0:0:0:1 or ::1.
You can read this how-to-guide for more information on the different ways to obtain IP address.