|
1 |
| -# ipapi-nodejs |
2 |
| -Node.js bindings for ipapi (IP address geolocation API) - https://ipapi.co/ |
| 1 | + |
| 2 | +# Node.js + ipapi (IP address location API) |
| 3 | + |
| 4 | +## Usage |
| 5 | + |
| 6 | +### From Node.js REPL |
| 7 | + |
| 8 | +``` |
| 9 | +var ipapi = require('./ipapi.js'); |
| 10 | +
|
| 11 | +var callback = function(res){ |
| 12 | + console.log(res); |
| 13 | +}; |
| 14 | +
|
| 15 | +ipapi.location(callback) // Complete location for your IP address |
| 16 | +> { |
| 17 | + ip: '50.1.2.3', |
| 18 | + city: 'Wilton', |
| 19 | + region: 'California', |
| 20 | + country: 'US', |
| 21 | + postal: 95693, |
| 22 | + latitude: 38.3926, |
| 23 | + longitude: -121.2429, |
| 24 | + timezone: 'America/Los_Angeles' |
| 25 | + } |
| 26 | +
|
| 27 | +
|
| 28 | +ipapi.location(callback, '', '', 'ip') // Your external IP address |
| 29 | +50.1.2.3 |
| 30 | +
|
| 31 | +ipapi.location(callback, '', '', 'city') // Your city |
| 32 | +Wilton |
| 33 | +
|
| 34 | +ipapi.location(callback, '', '', 'country') // Your country |
| 35 | +US |
| 36 | +
|
| 37 | +ipapi.location(callback, '8.8.8.8') // Complete location for IP address 8.8.8.8 |
| 38 | +> { |
| 39 | + ip: '8.8.8.8', |
| 40 | + city: 'Mountain View', |
| 41 | + region: 'California', |
| 42 | + country: 'US', |
| 43 | + postal: '94035', |
| 44 | + latitude: 37.386, |
| 45 | + longitude: -122.0838, |
| 46 | + timezone: 'America/Los_Angeles' |
| 47 | +} |
| 48 | +
|
| 49 | +ipapi.location(callback, '8.8.8.8', '', 'city') // City for IP address 8.8.8.8 |
| 50 | +Mountain View |
| 51 | +
|
| 52 | +ipapi.location(callback, '8.8.8.8', '', 'country') // Country for IP address 8.8.8.8 |
| 53 | +US |
| 54 | +``` |
| 55 | + |
| 56 | + |
| 57 | + |
| 58 | +### With API Key |
| 59 | + |
| 60 | +API key can be specified in the following ways : |
| 61 | + |
| 62 | +1. Inside `ipapi.js` by setting `API_KEY` variable |
| 63 | +2. As a function argument e.g. `ipapi.location(callback, '8.8.8.8', 'secret-key')` |
| 64 | + |
| 65 | + |
| 66 | +### Function arguments |
| 67 | +- Optional arguments (e.g. IP address, key, field) can be an empty string `''` or `undefined` |
0 commit comments