GET IP ADDRESS GEO DATA IN JAVASCRIPT 1

GET IP ADDRESS GEO DATA IN JAVASCRIPT

fetch(`https://ipinfo.io/USERIPADDRESS?token=YOUR-TOKEN-FROM-IPINFOSITE`).then(response => response.text()).then(data => {
	console.log(data)
});

Here is what the above code is Doing:
1. We’re using the fetch API to make a GET request to the ipinfo.io API.
2. We’re using the .then() method to wait for the response from the API.
3. We’re using the .text() method to convert the response to a string.
4. We’re using the .then() method to wait for the response to be converted to a string.
5. We’re logging the response to the console.

The response from the API will look something like this:

{
“ip”: “8.8.8.8”,
“hostname”: “google-public-dns-a.google.com”,
“city”: “Mountain View”,
“region”: “California”,
“country”: “US”,
“loc”: “37.3860,-122.0840”,
“org”: “AS15169 Google LLC”,
“postal”: “94035”,
“timezone”: “America/Los_Angeles”,
“readme”: “https://ipinfo.io/missingauth”
}

Similar Posts