get-public-ipv4
Version:
Fetches the public IP address using the ipify.org API
82 lines (52 loc) โข 1.15 kB
Markdown
# ๐ get-public-ipv4
Simple utility to get the **public IPv4 address** of your machine using the `ipify.org` API.
## ๐ฆ Installation
### Using npm
```bash
npm install get-public-ipv4
```
### Using yarn
```bash
yarn add get-public-ipv4
```
## ๐ Usage
```js
const getPublicIP = require("get-public-ipv4");
(async () => {
try {
const ip = await getPublicIP();
console.log("Public IPv4 address:", ip);
} catch (err) {
console.error("Failed to fetch public IP:", err);
}
})();
```
## โ๏ธ Options
No options are required.
The module performs a single HTTP request to retrieve the caller's public IP address.
## ๐ How it Works
This module sends a `GET` request to:
```
https://api.ipify.org?format=json
```
And returns your public IPv4 address in string format (e.g. `"85.105.12.34"`).
## ๐ค Output Example
```bash
Public IPv4 address: 85.105.12.34
```
## ๐งช Run Test
```bash
node test.js
```
> You can also run the function directly to see your current IP.
## ๐ชช License
```
MIT
```