# mmdb-reader

> Read IP data from MaxMind DB files

Latest version **1.2.0** (published 2018-07-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install mmdb-reader
pnpm add mmdb-reader
yarn add mmdb-reader
bun add mmdb-reader
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2018-07-02 |
| First published | 2015-07-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 27.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 46 |
| Author | JT |
| Maintainers | gosquared, jt |
| Keywords | geoip, geoip2, maxmind, mmdb |

## Links

- npm: https://www.npmjs.com/package/mmdb-reader
- Repository: https://github.com/gosquared/mmdb-reader
- Issues: https://github.com/gosquared/mmdb-reader/issues
- npm.io page: https://npm.io/package/mmdb-reader

## Dependencies (2)

- [hashlru](https://npm.io/package/hashlru.md) ^2.0.0
- [big-integer](https://npm.io/package/big-integer.md) ^1.5.4

## Alternatives

- [@mdxeditor/editor](https://npm.io/package/@mdxeditor/editor.md) — 962.4K weekly downloads
- [mmdb-lib](https://npm.io/package/mmdb-lib.md) — 680.9K weekly downloads
- [playcanvas](https://npm.io/package/playcanvas.md) — 36.2K weekly downloads
- [@glw907/cairn-cms](https://npm.io/package/@glw907/cairn-cms.md) — 967 weekly downloads
- [markdown-to-confluence](https://npm.io/package/markdown-to-confluence.md) — 103 weekly downloads

## Recent versions

- 1.2.0 (latest) — 2018-07-02
- 1.1.0 — 2017-02-17
- 1.0.1 — 2016-05-30
- 1.0.0 — 2016-02-12
- 0.0.4 — 2015-08-06
- 0.0.3 — 2015-07-23
- 0.0.2 — 2015-07-18
- 0.0.1 — 2015-07-13
- 0.0.0 — 2015-07-01

## README

# mmdb-reader

[![Travis](https://api.travis-ci.org/gosquared/mmdb-reader.svg)](https://travis-ci.org/gosquared/mmdb-reader)
[![Dependencies](https://david-dm.org/gosquared/mmdb-reader.svg)](https://david-dm.org/gosquared/mmdb-reader)
[![Join the chat at https://gitter.im/gosquared/mmdb-reader](https://img.shields.io/badge/gitter-join%20chat-blue.svg)](https://gitter.im/gosquared/mmdb-reader)

[![NPM](https://nodei.co/npm/mmdb-reader.png?downloads=true&downloadRank=true&stars=true)](https://www.npmjs.com/package/mmdb-reader)

Pure-JS reader for MaxMind DB (.mmdb) files, for looking up data indexed by IP address.

Inspired by [node-maxmind-db](https://github.com/PaddeK/node-maxmind-db), but faster.

## Installation

```sh
npm install mmdb-reader
```

## Usage

```js
var MMDBReader = require('mmdb-reader');

// Load synchronously
var reader = new MMDBReader('path/to/data.mmdb');

reader.lookup('8.8.8.8'); // { city: { ... }, continent: { ... } }

```

### Async Loading

```js
var MMDBReader = require('mmdb-reader');

MMDBReader.open('path/to/data.mmdb', function(err, reader){

  if(err){
    // something went wrong. Handle it somehow
  }

  reader.lookup('8.8.8.8'); // { city: { ... }, continent: { ... } }

});
```


## Assumptions

mmdb-reader loads the entire database file into memory as a single node `Buffer`. It also uses an in-memory cache when reading complex data structures out of this buffer in the interests of performance. So very roughly speaking, you should assume this module will consume `size_of_mmdb_file * 1.25` of memory.

The default behaviour is to load the database file synchronously. This assumes that CPU and I/O are less important to you when your process is starting than when it's booted and you need to look up IPs quickly. If you want to load the file asynchronously then obviously you don't have a `reader` until it's finished.

Results are returned directly from the in-memory cache by reference, so if you're going to be modifying data, you should copy it first. That is, don't do this:

```js
var record = reader.lookup('1.2.3.4');
record.something = 'foo';

// elsewhere:
var anotherRecord = reader.lookup('2.3.4.5');
// anotherRecord.something might be 'foo'. Or it might not. Who knows?
```

---
_Source: https://npm.io/package/mmdb-reader · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
