2

Is there any possible way to get client public ip from api request in node js ?

From request we can get only local ip ....

Vignesh G
  • 21
  • 2
  • Does this answer your question? [How to determine a user's IP address in node](https://stackoverflow.com/questions/8107856/how-to-determine-a-users-ip-address-in-node) – ridvanaltun Oct 11 '21 at 13:47

1 Answers1

1

In nodejs http callback:

request.socket.remoteAddress

if you have a load balancer environment:

(req.headers['x-forwarded-for'] || '').split(',')[0] || req.socket.remoteAddress

Xin
  • 33,823
  • 14
  • 84
  • 85
  • Update: Connection is deprecated. Use request.socket.remoteAddress instead https://nodejs.org/api/net.html#net_socket_remoteaddress – shyam Oct 09 '21 at 01:20