0

I Have created a sample website with react and nodejs. I want to fetch the user's IP address who fills the form(website form). I have used the below code on the backend for fetching IP.

const ip = req.headers['x-forwarded-for'] || req.socket.remoteAddress;
console.log('client ip', ip);

But not get success. Please, guys, suggest to me how to fetch the IP of the user without any other API( like https://ipgeolocation.abstractapi.com external API)

sudesh sharma
  • 55
  • 1
  • 9
  • Why don't you want to fetch the user's IP address from an external API? – KiprasT Oct 28 '21 at 06:52
  • its condition or requirement from the project team. @KiprasT – sudesh sharma Oct 28 '21 at 06:58
  • Well then the short answer is you can't as Reactjs (like any other JS web app) runs on client side (source: https://stackoverflow.com/questions/391979/how-to-get-clients-ip-address-using-javascript/). You could do some server side rendering before serving your client the actual app. – KiprasT Oct 28 '21 at 07:03

0 Answers0