Well, from my experience, the easiest way to javascript get ip address is to use a free external API. A solid choice I’ve used in projects is ipify. It’s incredibly simple. You just make a GET request to their API, and voilà! Here’s a basic example:
fetch('https://api.ipify.org?format=json')
.then(response => response.json())
.then(data => console.log('Your IP is:', data.ip))
.catch(err => console.error('Error fetching IP:', err));
I’ve used this in dashboards during development to log visitor info. It’s clean, reliable, and takes just seconds to implement. Totally recommend it for quick setups.