Published on

Getting Your Public IP Address in JavaScript

Authors

If you want to get a public IP address then public-ip npm package might be a good choice for you.

With this library, you can easily get IP addresses both IPv4 and IPv6. And it supports both the browser and node as well.

Dependency

npm install public-ip

Snippet

import {publicIp, publicIpv4, publicIpv6} from 'public-ip';
console.log(await publicIp()); // Falls back to IPv4
console.log(await publicIpv6()); // IPv6: fe80::200:f8ff:fe21:67cf
console.log(await publicIpv4()); // IPv4: 192.166.0.0

Happy getting-public IP!