IP lookup using Maxmind databases
npm install maxmindJavascript module for Geo IP lookup using Maxmind binary databases (aka mmdb or geoip2).
Fastest Maxmind lookup library available - up to 17,000% 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 using other formats.
You might want to use geolite2 module with free geo databases. Alternatively, free databases available for download here. If you need better accuracy you should consider buying commercial subscription.
``shell`
npm i maxmind
`typescript
import maxmind, { CityResponse } from 'maxmind';
const lookup = await maxmind.open
console.log(lookup.get('66.6.44.4')); // inferred type maxmind.CityResponse
console.log(lookup.getWithPrefixLength('66.6.44.4')); // tuple with inferred type [maxmind.CityResponse|null, number]
`
You can use Reader class directly in case if you would want to instantiate it in non-async fashion. Use cases would include receiving a buffer database over network, or just reading it synchronously from disk.
`typescript
import { Reader } from 'maxmind';
const buffer = fs.readFileSync('./db.mmdb');
const lookup = new Reader
const city = lookup.get('8.8.8.8');
const [city2, prefixLength] = lookup.getWithPrefixLength('66.6.44.4');
`
Supported response types:
``
- CountryResponse
- CityResponse
- AnonymousIPResponse
- AsnResponse
- ConnectionTypeResponse
- DomainResponse
- IspResponse
Module is fully compatible with IPv6. There are no differences in API between IPv4 and IPv6.
`javascript`
const lookup = await maxmind.open('/path/to/GeoLite2.mmdb');
const location = lookup.get('2001:4860:0:1001::3004:ef68');
_maxmind.open(filepath, [options])_
- filepath: Path to the binary mmdb database file.options
- :
Current module is designed to work in node.js environment. Check out mmdb-lib that's used under the bonnet - it's environment agnostic and does work in browser.
Module supports validation for both IPv4 and IPv6:
`javascript
maxmind.validate('66.6.44.4'); // returns true
maxmind.validate('66.6.44.boom!'); // returns false
maxmind.validate('2001:4860:0:1001::3004:ef68'); // returns true
maxmind.validate('2001:4860:0:1001::3004:boom!'); // returns false
``
In case you want to use legacy GeoIP binary databases you should use maxmind@0.6.
- MMDB library
- 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