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 🙏

© 2026 – Pkg Stats / Ryan Hefner

ipgeolocation-mmdb-reader

v1.0.0

Published

Plain Node.js reader for IPGeolocation MMDB files

Readme

IPGeolocation MMDB Reader for Node.js

A fast, minimal, dependency-free Node.js reader for MMDB database files.

  • Zero runtime dependencies
  • Supports IPv4 and IPv6 lookups
  • Works with IPGeolocation.io MMDB databases and other MaxMind DB format files
  • CommonJS package
  • TypeScript declarations included

Requirements

  • Node.js 16 or later
  • An MMDB database file

Installation

npm install ipgeolocation-mmdb-reader

Getting a Database

To use this package, you need an MMDB file. You can use your own MMDB database or download database samples from IPGeolocation.io:

https://ipgeolocation.io/ip-geolocation-database.html

Downloaded database files may be compressed, so unzip them before passing the .mmdb file path to the reader.

Quick Start

const { IPGeolocationMMDBReader } = require("ipgeolocation-mmdb-reader");

const reader = new IPGeolocationMMDBReader("db-ip-city-company-asn.mmdb");

const result = reader.lookup("1.1.1.1");

if (result === null) {
  console.log("No match");
} else {
  console.log(JSON.stringify(result, null, 2));
}

reader.close();

Metadata

const { IPGeolocationMMDBReader } = require("ipgeolocation-mmdb-reader");

const reader = new IPGeolocationMMDBReader("db-ip-city-company-asn.mmdb");

console.log(JSON.stringify(reader.getMetadata(), null, 2));

reader.close();

API

new IPGeolocationMMDBReader(filename)

Loads an MMDB file from disk and parses its metadata.

lookup(ip)

Looks up a single IPv4 or IPv6 address.

Returns the decoded database record, or null if no matching record exists.

const result = reader.lookup("8.8.8.8");

lookupMany(ips)

Looks up multiple IP addresses and returns an array of [ip, result] pairs.

Each result is either the decoded database record or null if no matching record exists.

const results = reader.lookupMany(["1.1.1.1", "8.8.8.8"]);

for (const [ip, result] of results) {
  console.log(ip, result);
}

getMetadata()

Returns a shallow copy of the MMDB metadata object.

close()

Clears internal caches.

The reader loads the file into memory, so there is no open file descriptor after construction.

Errors

The package exports custom error classes so callers can distinguish invalid input, invalid database files, and unsupported MMDB layouts.

MMDBError

Base error for reader-specific failures.

This is also raised when an IP address string is invalid, or when an IPv6 address is queried against an IPv4-only database.

MetadataError

Raised when the file does not look like a valid MMDB database, the metadata marker cannot be found, or required metadata fields are missing.

CorruptDatabaseError

Raised when the database structure is inconsistent, such as invalid map keys, invalid boolean encoding, container length mismatch, or overlapping data and metadata sections.

UnsupportedRecordSizeError

Raised when the database uses an unsupported MMDB record size. This reader supports record sizes 24, 28, and 32.

const {
  IPGeolocationMMDBReader,
  MMDBError,
  MetadataError,
  CorruptDatabaseError,
  UnsupportedRecordSizeError,
} = require("ipgeolocation-mmdb-reader");

try {
  const reader = new IPGeolocationMMDBReader("database.mmdb");
  const result = reader.lookup("1.1.1.1");
  console.log(result);
  reader.close();
} catch (error) {
  if (error instanceof MetadataError) {
    console.error("The MMDB file metadata is missing or invalid.");
  } else if (error instanceof CorruptDatabaseError) {
    console.error("The MMDB file appears to be corrupt.");
  } else if (error instanceof UnsupportedRecordSizeError) {
    console.error("The MMDB record size is not supported.");
  } else if (error instanceof MMDBError) {
    console.error(error.message);
  } else {
    throw error;
  }
}

TypeScript

Type declarations are included.

import { IPGeolocationMMDBReader } from "ipgeolocation-mmdb-reader";

const reader = new IPGeolocationMMDBReader("database.mmdb");
const result = reader.lookup("1.1.1.1");
reader.close();

License

MIT