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

  • 0.4.1
  • Source
  • npm
  • Socket score

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

node-maxmind Build Status

Native Javascript module for IP GEO lookup using Maxmind databases. Up to 500% faster than other GEO lookip libraries. No binary or whatsoever dependencies.

GEO databases

Free GEO databases available for download here: http://dev.maxmind.com/geoip/geolite.

Installation

npm i maxmind

Main features

  • Country/Region/Location lookup by IP
  • Distance between two IP addresses (locations)
  • Timezone lookup by IP
  • Autonomous System Numbers (ASN) lookup by IP

Module written in pure Javascript with no dependencies. Being able to work with binary Maxmind databases it doesn't require any "CSV - {specific lib format}" conversions as other modules do. Maxmind binary databases are highly optimized for size and performance so there's no point working with other than that format.

Usage

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

var maxmind = require('maxmind');

// City/Location lookup
maxmind.init('/path/to/GeoLiteCity.dat');
var location = maxmind.getLocation('66.6.44.4');

// Country Lookup
maxmind.init('/path/to/GeoIP.dat');
var country = maxmind.getCountry('66.6.44.4');

// Autonomous System Numbers (ASN) lookup
maxmind.init('/path/to/GeoIPASNum.dat');
var org = maxmind.getOrganization('66.6.44.4');

You can initialize module with several databases at once, and proper db will be automatically selected for particular query. If any options given they apply for all databases you initialize.

var maxmind = require('maxmind');
maxmind.init(['/path/to/GeoLiteCity.dat', '/path/to/GeoIPASNum.dat']);
// now both org and location lookups will work
var org = maxmind.getOrganization('66.6.44.4');
var location = maxmind.getLocation('66.6.44.4');

Options

By default module does not use cache, and works directly with file system. Enabling cache leads to better performance though consumes more memory.

  • indexCache saves in memory the country index only
  • memoryCache saves in memory full database file
  • checkForUpdates checks databases for updates (via fs mtime). Basically once you replace the old DB file with the new one module automamtically re-initialises.

Options can be passed to init method:

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

Performance / Benchmark

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

  • default: 20,000 lookups / second
  • indexCache: 115,000 lookups / second
  • memoryCache: 270,000 lookups / second

Following benchmark is made for GeoIPCity database. Memory caching is enabled where possible. If you believe that benchmark is not realistic please post a PR and share your code :)

node-maxmind  274649 op/sec
geoip-lite    191681 op/sec 43.28% slower
geoip         43483 op/sec  531.61% slower

Contributing

Make sure you run npm i command in the project's dir before you begin, it'll install all dev dependencies. Currently code coverage is about 85%, so new tests are essential when you add new functionality. There're several npm tasks which you can find useful:

  • npm test runs tests
  • npm run lint runs js linter
  • npm run coverage runs code coverage task and generates report
  • npm run benchmark runs basic benchmark

One pull request per one feature, nothing unusual.

References

License

MIT

Keywords

FAQs

Package last updated on 10 Mar 2014

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