Node.js client for its Restify server counterpart: node-geoip2-api. This module is best used in conjunction with its counterpart. It prevents the developer from constructing API requests manually.
npm install node-geoip2-client --save
Create a new GeoIP2 API instance by calling the constructor.
var Client = require('node-geoip2-client')
, client = new Client({
host: '129.123.237.21', // defaults to localhost
protocol: 'https', // defaults to http
port: '443', // defaults to 8082
timeout: 1E3 // defaults to 5000 ms
});
The client has several methods available to query the MaxMind GeoIP2 database.
Query the database by IP. The client will perform a request to the configured server and return the results.
- ip: {String} required query database by IP.
- callback: {Function} required Completion callback.
client.get('172.213.123.21', function (error, result) {
console.log(result); // results parsed as JSON
});
Node-geoip2-client is released under MIT.