Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Maxmind GEO Lookup
JavaScript
Tree: 48c4dcd75c

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
examples
lib
test
tools
.gitignore
README.md
benchmark.js
index.js
package.json

README.md

node-maxmind

IP geo lookup using Maxmind databases, written in pure javascript.

GEO databases

You can download free geo databases here: http://dev.maxmind.com/geoip/geolite.

Installation

npm install maxmind

Main features

  • Location lookup
  • Country lookup
  • Distance between two IP addresses (locations)
  • Timezone lookup by IP

Usage

** see code samples in ./examples directory **

City/Location lookup

    var maxmind = require('maxmind');
    maxmind.init('/path/to/GeoLiteCity.dat');
    console.log(maxmind.getLocation("66.6.44.4"));

Country Lookup

    var maxmind = require('maxmind');
    maxmind.init('/path/to/GeoIP.dat');
    console.log(maxmind.getCountry("66.6.44.4"));

Caching

By default module does not use cache, and works directly with file system. Enabling cache leads to better performance, howerver consumer more memory. Currently module supports two options:

  • indexCache saves in memory only the country index
  • memoryCache saves in memory full database file

If you decided to enable caching you can pass it as a flag in init method:

    var maxmind = require('maxmind');
    maxmind.init('/path/to/GeoIP.dat', { indexCache: true });

Caching could significantly increase performance, refer to this camparison which was made on average laptop:

  • default: 18,000 lookups / second
  • indexCache: 60,000 lookups / second
  • memodyCache: 100,000 lookups / second

Tests

If you want ot run tests you will need mocha installed, then just run it:

$ mocha

Disclaimer

Module is quite young and serious bugs are possible. Feel free to send pull request / bug reports.

Something went wrong with that request. Please try again.