UNPKG

get-public-ipv4

Version:

Fetches the public IP address using the ipify.org API

82 lines (52 loc) โ€ข 1.15 kB
# ๐ŸŒ 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 ```