getlocation

gets ip location information from user

Usage no npm install needed!

<script type="module">
  import getlocation from 'https://cdn.skypack.dev/getlocation';
</script>

README

getLocation

The getlocation library exported as Node.js modules.

Docs

Gets location data based on IP address.
There are 4 providers available - you can add more

Returns:

{ city: 'Montana Hill',
country: 'Canada',
countryCode: 'CA',
gps: { long: 13.8669, latt: -29.4414 },
region: 'MB',
regionName: 'Manatoba' }

Installation

npm install getlocation

Params

Get location requires 2 paramiters unless the provider requires an APIKEY, then provide the last Please note: the API keys in this document are fake, they do not work - get your own

  1. Provider - currently supported, select one and use the integer
    default: http://freegeoip.net
    1: http://freegeoip.net
    2: http://www.telize.com
    3: http://ip-api.com
    4: http://api.ipinfodb.com

  2. IP Address to locate - string '99.250.84.161'

  3. API key is provider requires it - string
    (check your provider - currently 'ipinfodb.com' requires one, you can register for one)

Init

var makeid = require('getlocation');

Create a Random String

To get a location - no api needed:

try{
    IPLocation(0, '99.250.84.164', (result, error) => {
        console.log(result);
    });
    
}catch(err){
    console.log(err);
}

To get a location - with api needed:

try{
    IPLocation(4, '99.250.84.161', 'dcec64de3c44deb133918a912ff5bc0e902de1a17ebdcd396358571b21ff8672', (result, error) => {
        console.log(result);
    });
    
}catch(err){
    console.log(err);
}

Support

Tested in Chrome 53-54, Firefox 48-49, IE 11, Edge 14, Safari 9-10, Node.js 6-7, & PhantomJS 2.1.1.
Automated test runs are available.