ipify
Version:
Get your public IP address
84 lines (53 loc) • 1.82 kB
Markdown
public IP address
Using the [Ipify API](https://www.ipify.org) or a [custom Ipify instance](https://github.com/rdegges/ipify-api).
```sh
npm install ipify
```
```js
import ipify from 'ipify';
console.log(await ipify());
//=> '2001:0db8:85a3:0000:0000:8a2e:0370:7334'
```
Returns a `Promise<string>` with an IP address.
Type: `object`
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.
```js
import ipify from 'ipify';
console.log(await ipify({useIPv6: false}));
//=> '82.142.31.236'
```
Type: `string | string[]`\
Default: `'https://api6.ipify.org'`
Custom API endpoint.
Can be a single endpoint or an array of endpoints. When multiple endpoints are provided, they will be tried concurrently and the first successful response will be returned.
```js
import ipify from 'ipify';
// Single endpoint
console.log(await ipify({endpoint: 'https://api.ipify.org'}));
//=> '82.142.31.236'
// Multiple endpoints for resilience
console.log(await ipify({
endpoint: [
'https://api.ipify.org',
'https://ipify.example.org'
]
}));
//=> '82.142.31.236'
```
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.
- [ipify-cli](https://github.com/sindresorhus/ipify-cli) - CLI for this package
- [internal-ip](https://github.com/sindresorhus/internal-ip) - Get your internal IPv4 or IPv6 address
> Get your