npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

maxmind-db-reader

v0.2.1

Published

This is the pure Node API for reading MaxMind DB files. MaxMind DB is a binary file format that stores data indexed by IP address subnets (IPv4 or IPv6).

Downloads

12,958

Readme

node-maxmind-db

This is the pure Node API for reading MaxMind DB files. MaxMind DB is a binary file format that stores data indexed by IP address subnets (IPv4 or IPv6).

WARNING

  • .open(Sync) needs to be called once before abusing .getGeoData(Sync)
  • this is version 0.1.0! the API is not compitable with 0.0.*
  • Most IP's don't seem to have city data in the GeoLite2 City database. Only american cities are present, if your IP is american but not returning a city try to replace the last number of your IP by a 0 (only with a IPv4 address. for IPv6 address it doesn't seem to work).

Install

npm i maxmind-db-reader

Example

Async

// require the db reader
var mmdbreader = require('maxmind-db-reader');
// open database
mmdbreader.open('./countries.mmdb',function(err,countries){
    // get geodata
    countries.getGeoData('128.101.101.101',function(err,geodata){
        // log data :D
        console.log(geodata);
    });
});

Sync

// require the db reader
var mmdbreader = require('maxmind-db-reader');
//  open database
var countries = mmdbreader.openSync('./countries.mmdb');
// get geodata
var geodata = countries.getGeoDataSync('128.101.101.101');
// log data :D
console.log(geodata);

Mixed (Sync init, Async request)

// require the db reader
var mmdbreader = require('maxmind-db-reader');
// open database
var countries = mmdbreader.openSync('./countries.mmdb');
// get geodata
countries.getGeoData('128.101.101.101',function(err,geodata){
    // log data :D
    console.log(geodata);
});

Result

{
    "city": {
        "geoname_id": 5037649,
        "names": {
            "de": "Minneapolis",
            "en": "Minneapolis",
            "es": "Mineápolis",
            "fr": "Minneapolis",
            "ja": "ミネアポリス",
            "pt-BR": "Minneapolis",
            "ru": "Миннеаполис",
            "zh-CN": "明尼阿波利斯"
        }
    },
    "continent": {
        "code": "NA",
        "geoname_id": 6255149,
        "names": {
            "de": "Nordamerika",
            "en": "North America",
            "es": "Norteamérica",
            "fr": "Amérique du Nord",
            "ja": "北アメリカ",
            "pt-BR": "América do Norte",
            "ru": "Северная Америка",
            "zh-CN": "北美洲"
        }
    },
    "country": {
        "geoname_id": 6252001,
        "iso_code": "US",
        "names": {
            "de": "USA",
            "en": "United States",
            "es": "Estados Unidos",
            "fr": "États-Unis",
            "ja": "アメリカ合衆国",
            "pt-BR": "Estados Unidos",
            "ru": "США",
            "zh-CN": "美国"
        }
    },
    "location": {
        "latitude": 44.9759,
        "longitude": -93.2166,
        "metro_code": "613",
        "time_zone": "America/Chicago"
    },
    "postal": {
        "code": "55414"
    },
    "registered_country": {
        "geoname_id": 6252001,
        "iso_code": "US",
        "names": {
            "de": "USA",
            "en": "United States",
            "es": "Estados Unidos",
            "fr": "États-Unis",
            "ja": "アメリカ合衆国",
            "pt-BR": "Estados Unidos",
            "ru": "США",
            "zh-CN": "美国"
        }
    },
    "subdivisions": [
        {
            "geoname_id": 5037779,
            "iso_code": "MN",
            "names": {
                "en": "Minnesota",
                "es": "Minnesota",
                "ja": "ミネソタ州",
                "ru": "Миннесота"
            }
        }
    ]
}

API

maxmind-db-reader

  • .open (databasePath, callback(err, maxmind-db-reader)) void
  • .openSync (databasePath) maxmind-db-reader

maxmind-db-reader()

  • .getGeoData (ip, callback(err,geodata)) void
  • .getGeoDataSync (ip) geodata
  • .getDatabaseMetadata() metadata