How to get the IP address from HTTP request url or the client IP from where my node code is running.
http://127.0.0.1:1000/samp/
The client IP can be an nginx IP or public IP. Any help on this will be really helpful.
Thanks.
How to get the IP address from HTTP request url or the client IP from where my node code is running.
http://127.0.0.1:1000/samp/
The client IP can be an nginx IP or public IP. Any help on this will be really helpful.
Thanks.
Assuming you want the client ip, you'll need to first decide if you trust "X-Forwarded-For" headers (that is: you are behind a reverse proxy that you yourself set up and which you trust, or you trust the proxies along the way).
If so, then get the ip in req.headers['x-forwarded-for']
(this could potentially be a list).
If not, then req.connection.remoteAddress
is the answer.
Try this
app.get('/', function(req, res) {
res.send(req.connection.remoteAddress);
});