const realClientIpAddress = (req.headers['x-forwarded-for'] || req.ip || "").split(',')
const ip = realClientIpAddress[realClientIpAddress.length - 1]
X-Forwarded-For is appended-to for every proxy the request passes through. You want the first IP address, not the last one.Example, if your app was on Heroku behind Cloudflare, the request will look like this:
IP: <Heroku's load balancer addr>
X-Forwarded-For: <Real user addr>, <Cloudflare addr>
Your code, as written, will be geolocating the Cloudflare node.