New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

maxmind

Package Overview
Dependencies
Maintainers
1
Versions
93
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

maxmind

IP lookup using Maxmind databases

  • 2.5.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
77K
decreased by-53.02%
Maintainers
1
Weekly downloads
 
Created
Source

node-maxmind Build Status

Pure Javascript 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 working with other than that format.

GEO databases

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.

Installation

npm i maxmind

Usage

var maxmind = require('maxmind');

maxmind.open('/path/to/GeoLite2-City.mmdb', (err, cityLookup) => {
  var city = cityLookup.get('66.6.44.4');
});

maxmind.open('/path/to/GeoOrg.mmdb', (err, orgLookup) => {
  var city = 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.

var cityLookup = maxmind.openSync('/path/to/GeoLite2-City.mmdb');
var city = cityLookup.get('66.6.44.4');

var orgLookup = maxmind.openSync('/path/to/GeoOrg.mmdb');
var organization = orgLookup.get('66.6.44.4');

V6 Support

Module is fully compatible with IPv6. There are no differences in API between IPv4 and IPv6.

var lookup = maxmind.openSync('/path/to/GeoLite2.mmdb');
var location = lookup.get('2001:4860:0:1001::3004:ef68');

Options

cache

Module uses tiny-lru. You can configure its settings by doing following:

var lookup = maxmind.openSync('/path/to/GeoLite2.mmdb', {
  cache: {
    max: 500, // Max items in cache, by default it's 6000
  }
});
lookup.get('1.1.1.1');

watchForUpdates

Supports reloading the reader when changes occur to the database that is loaded. (default false). Only supported by Node v0.5.10+.

var lookup = maxmind.openSync('/path/to/GeoLite2.mmdb', { watchForUpdates: true });
lookup.get('1.1.1.1');

IP addresses validation

Module supports validation for both IPv4 and IPv6:

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

GeoIP Legacy binary format

In case you want to use legacy GeoIP binary databases you should use maxmind@0.6.

References

License

MIT

Keywords

FAQs

Package last updated on 02 Mar 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc