1.0.0 • Published 9 years ago

node-geoip2-api v1.0.0

Weekly downloads
144
License
MIT
Repository
github
Last release
9 years ago

node-geoip2-api

Version npmBuild StatusDependenciesCoverage Status

Node.js API for MaxMind GeoIP2 databases. Best used with the node-geoip2-client.

Installation

npm install node-geoip2-api --save

If you'd like to download the latest city database, simply run

npm run setup

Server

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
});

Standalone instance

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
    });

API

The server has several methods available to query the MaxMind GeoIP2 database.

client.get

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
});

License

Node-geoip2-api is released under MIT.