Created
August 9, 2018 17:12
-
-
Save asharirfan/c41744e89127ac8c6b919ee88fbe34a8 to your computer and use it in GitHub Desktop.
Query GeoIP Lookup of an IP Address using simple-geoip
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Include the package. | |
const simpleGeoIP = require('simple-geoip'); | |
// Create a new instance of the package using your API key. | |
let geoIP = new simpleGeoIP('YOUR_API_KEY'); | |
// Send a request for GeoIP lookup. | |
geoIP.lookup('8.8.8.8', (err, data) => { | |
if (err) throw err; // Look for errors (if any). | |
console.log(data); // Dump the results to the log. | |
}); | |
// Sample response that you will get from the API. | |
{ | |
"ip": "8.8.8.8", | |
"location": { | |
"country": "US", | |
"region": "California", | |
"city": "Mountain View", | |
"lat": 37.40599, | |
"lng": -122.078514, | |
"postalCode": "94043", | |
"timezone": "-08:00" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment