# maxmind-db-reader

> 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).

Latest version **0.2.1** (published 2015-07-24) · 0 weekly downloads

## Install

```sh
npm install maxmind-db-reader
pnpm add maxmind-db-reader
yarn add maxmind-db-reader
bun add maxmind-db-reader
```

Provides the command `mmdb-geoip`.

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.1 |
| Published | 2015-07-24 |
| First published | 2013-10-17 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 87 |
| Author | Patrick Klös |
| Maintainers | paddek, eaterofcode |
| Keywords | Maxmind, Maxmind DB, Maxmind DB Reader, GeoIP2, GeoIP2 Lite |

## Links

- npm: https://www.npmjs.com/package/maxmind-db-reader
- Repository: https://github.com/PaddeK/node-maxmind-db
- Homepage: https://github.com/PaddeK/node-maxmind-db#readme
- Issues: https://github.com/PaddeK/node-maxmind-db/issues
- npm.io page: https://npm.io/package/maxmind-db-reader

## Dependencies (2)

- [ip-address](https://npm.io/package/ip-address.md) 4.0.0
- [big-integer](https://npm.io/package/big-integer.md) >=1.1.5

## Recent versions

- 0.2.1 (latest) — 2015-07-24
- 0.1.1 — 2015-05-06
- 0.2.0 — 2014-06-04
- 0.0.2 — 2013-10-17
- 0.0.1 — 2013-10-17

## 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
```javascript
// 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
```javascript
// 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)

```javascript
// 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
```javascript
{
    "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`

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