ipify
Get your public IP address
Using the Ipify API or a custom Ipify instance.
Install
npm install ipify
Usage
import ipify from 'ipify';
console.log(await ipify());
API
ipify(options?)
Returns a Promise<string>
with an IP address.
options
Type: object
useIPv6
Type: boolean
Default: true
Use the IPv6 API endpoint. The IPv6 endpoint will return an IPv6 address if available, IPv4 address otherwise.
Setting the endpoint
option will override this.
import ipify from 'ipify';
console.log(await ipify({useIPv6: false}));
endpoint
Type: string
Default: 'https://api6.ipify.org'
Custom API endpoint.
FAQ
How is this different from public-ip
?
This package only targets the Ipify service, while public-ip
targets multiple services, is faster, and more resilient. Unless you run your own Ipify instance, you probably want public-ip
instead.
Related