How to get user's ip address in JavaScript

An IP address is a unique numerical label given to a computer when connected to a network;

ipify.org is a free service that retrieves IP addresses in JSON format

fetch('https://api.ipify.org?format=json')
.then(response => response.json())
.then(response => console.log(JSON.stringify(response)))

// response
{"ip":"--.---.---.---"}

In nodejs you can use a package node-fetch

Install it by typing;

npm i node-fetch

Or using curl, in your terminal type;

curl 'https://api6.ipify.org?format=json'

// response
{"ip":"--.---.---.---"}

Comments

Popular posts from this blog

FlappingBird Postmortem (JS13K)

JavaScript introduction to variables

FlappingBird JS13K Games

How to target all elements of a given class name in JavaScript

Zedplug will be decommissioned on November 30th