Node.js API for MaxMind GeoIP2 databases. Best used with the node-geoip2-client.
npm install node-geoip2-api --save
If you'd like to download the latest city database, simply run
npm run setup
The easiest method to run a server instance is by using the CLI tool, providing a port is optional.
PORT=8082 npm run server
To create and expose a Restify server instance, do the following. Note: the server instance will automatically listen to the provided port, unless told otherwise.
var server = require('node-geoip2-api').createServer(8082, {
listen: false
});
Create a standalone GeoIP2 API instance by directly calling the constructor. Note: this will not start a server on a port but exposes the prototype methods.
var API = require('node-geoip2-api')
, api = new API(null, {
db: '/path/to/database' // defaults to __dirname/db.mmdb
});
The server has several methods available to query the MaxMind GeoIP2 database.
Query the database by IP. The api will directly query the database on the filesystem and return the results.
- ip: {String} required query database by IP.
- callback: {Function} required Completion callback.
api.get('172.213.123.21', function (error, result) {
console.log(result); // results parsed as JSON
});
Node-geoip2-api is released under MIT.