ip-location
Fetch the location of an IP address, host name, or your own location.
Uses freegeoip.net to query for information. freegeoip.net uses MaxMind Geolite 2.
Install
npm i --save ip-location
Usage
With Callbacks
var ipLocation =
Outputs:
{ ip: '192.30.252.129',
country_code: 'US',
country_name: 'United States',
region_code: 'CA',
region_name: 'California',
city: 'San Francisco',
zip_code: '94107',
time_zone: 'America/Los_Angeles',
latitude: 37.7697,
longitude: -122.3933,
metro_code: 807 }
With Promises
var ipLocation =
Set Your Own Promise Implementation
You can set your own Promise library if you want to use Bluebird or are using Node v0.10.
var ipLocation = ipLocationPromise =
Use in Browser / or Use Own HTTP Library
If you want to use this in the browser, you must bring your own http GET library to the party. I'd recommend: xhr or fetch.
var ipLocation = ipLocation { }
Fetch Your Location
Just pass in an empty string.
Related
- ip-location-cli - Command line utility for this module.
License
MIT - Copyright (c) JP Richardson