Pure Javascript module for Geo IP lookup using Maxmind binary databases (aka mmdb or geoip2). Fastest Maxmind lookup library available - up to 8000% faster than other libraries. Module has 100% test coverage with comprehensive test suite. It natively works with binary Maxmind database format and doesn't require any "CSV - {specific lib format}" conversions as some other modules do. Maxmind binary databases are highly optimized for size and performance so there's no point working with other than that format.
Free GEO databases are available for download here. If you need better accuracy you should consider buying commercial subscription.
npm i maxmindvarmaxmind=require('maxmind');maxmind.open('/path/to/GeoLite2-City.mmdb',(err,cityLookup)=>{varcity=cityLookup.get('66.6.44.4');});maxmind.open('/path/to/GeoOrg.mmdb',(err,orgLookup)=>{varcity=orgLookup.get('66.6.44.4');});// Be careful with sync version! Since mmdb files// are quite large (city database is about 100Mb)// `fs.readFileSync` blocks whole process while it// reads file into buffer.varcityLookup=maxmind.openSync('/path/to/GeoLite2-City.mmdb');varcity=cityLookup.get('66.6.44.4');varorgLookup=maxmind.openSync('/path/to/GeoOrg.mmdb');varorganization=orgLookup.get('66.6.44.4');Module is fully campatible with IPv6. There are no differences in API between IPv4 and IPv6.
varlookup=maxmind.openSync('/path/to/GeoLite2.mmdb');varlocation=lookup.get('2001:4860:0:1001::3004:ef68');Right now the only option you can configure is cache. Module uses lru-cache. You can configure its settings by doing following:
varlookup=maxmind.openSync('/path/to/GeoLite2.mmdb',{cache: {max: 1000,// max items in cachemaxAge: 1000*60*60// life time in milliseconds}})lookup.get('1.1.1.1');Module supports validation for both IPv4 and IPv6:
maxmind.validate('66.6.44.4');// returns truemaxmind.validate('66.6.44.boom!');// returns falsemaxmind.validate('2001:4860:0:1001::3004:ef68');// returns truemaxmind.validate('2001:4860:0:1001::3004:boom!');// returns falseIn case you want to use legacy GeoIP binary databases you should use maxmind@0.6.
- Loosely based on https://github.com/PaddeK/node-maxmind-db
- MaxMind DB file format specification http://maxmind.github.io/MaxMind-DB/
- MaxMind test/sample DB files https://github.com/maxmind/MaxMind-DB
- GeoLite2 Free Downloadable Databases http://dev.maxmind.com/geoip/geoip2/geolite2/
- Great talk about V8 performance https://www.youtube.com/watch?v=UJPdhx5zTaw
- V8 Optimization killers https://github.com/petkaantonov/bluebird/wiki/Optimization-killers
- More V8 performance tips http://www.html5rocks.com/en/tutorials/speed/v8/
MIT
