maxminded
Version:
Auto updating maxmind GeoIP lookup for free and paid maxmind accounts and optional cloudflare fallback
103 lines (74 loc) • 5.54 kB
Markdown
# maxminded [](http://badge.fury.io/js/maxminded) [](https://travis-ci.org/angleman/maxminded/builds) [](https://gemnasium.com/angleman/maxminded) [](#licensemit)
Auto updating maxmind GeoIP lookup for free and paid maxmind accounts with optional cloudflare fallback. Leveringing the excellent [node-maxmind](https://github.com/runk/node-maxmind) package, **maxminded** manages regular data updates and provides an ultrafast geoip lookup fallback via [geos-major](https://github.com/angleman/geos-major) and [CloudFlare](https://cloudflare.com) headers when there is a maxmind IP lookup miss.
## Install :hammer:
```
npm install maxminded
```
## Usage :wrench:
Drop in compatible with [node-maxmind](https://github.com/runk/node-maxmind) when using free [Maxmind GeoLiteCity](http://dev.maxmind.com/geoip/legacy/geolite/) data.
```js
maxmind = require('maxminded');
maxmind.init('GeoLiteCity.dat'); // local init data & free Wednesday updates
location = maxmind.getLocation('66.6.44.4'); // City/Location lookup
```
## Free to paid geo data example :wrench:
Start with local free data, until initial paid data is loaded and then do paid data updates every Wednesday.
```js
maxminded = require('maxminded');
maxminded.init({
initLoad: 'GeoLiteCity.dat', // immediately initialize with local free data
memoryCache: true, // use memory cache for geo lookups
license: 'S0meK3yIdHere', // paid MAXMIND license key
start: true // begin initial paid date update
}, function(err) { // callback when re-initialized with paid data
if (err) console.log(err)
});
geo = maxminded.getLocation('66.6.44.4');
```
## Paid geo data example :wrench:
Use paid data and initialize doing updates every Wednesday and fallback to CloudFlare data until initial download and initialize completes or when maxmind.getLocation() fails to match an ip.
This requires [CloudFlare](http://cloudflare.com) to be enabled for your domain so the cf-country header will be populated.
```js
maxminded = require('maxminded');
maxminded.init({
start: true // begin initial free date update
}, function(err) {
if (err) console.log(err)
});
geo = maxmind.getLocation('66.6.44.4', req.headers); // pass in request headers for fallback
```
In this example, getLocation() will return ```undefined``` until the initial data is loaded and there is no cf-country header
## Optional parameters with defaults :bulb:
```js
maxminded.init({
cronTime: '00 30 03 * * 3', // update every Wednesday at 3:30am
dest: '/tmp/', // where geo updates are stored
retries: 5, //
}, function(err) { // callback when maxmind.init() occurs
console.log(err);
})
```
For additional parameter details see: [node-maxmind](https://github.com/runk/node-maxmind) and [maxmind-loader](https://github.com/angleman/maxmind-loader) and [node-cron](https://github.com/ncb000gt/node-cron)
## Note for PaaS users (like nodejitsu)
A bonus of using maxminded is that your geo data doesn't need to be pushed to your PaaS with your code deploy. The geo ip data can be pulled directly from maxmind in compressed form when your application launches.
```js
maxminded.init({start: function() {
var geo = maxminded.getLocation('66.6.44.4'); // GeoCityLite loaded w/weekly updates
}});
```
## License: MIT
<!--- :angleman@license-md/begin -->
Dependencies:
[](http://github.com/ncb000gt/node-cron)
[](https://github.com/angleman/geos-major)
[](https://github.com/runk/node-maxmind)
[](https://github.com/angleman/maxmind-reload)
[")](https://github.com/TooTallNate/node-time)
Development Dependencies:
[](https://github.com/gruntjs/grunt)
[](https://github.com/vojtajina/grunt-bump)
[](https://github.com/AceMetrix/grunt-license)
[](https://github.com/angleman/license-md)
[](https://github.com/visionmedia/mocha)
[")](https://github.com/visionmedia/should.js)
<!--- :angleman@license-md/end -->