Gathering detailed insights and metrics for @maxmind/geoip2-node
Gathering detailed insights and metrics for @maxmind/geoip2-node
Gathering detailed insights and metrics for @maxmind/geoip2-node
Gathering detailed insights and metrics for @maxmind/geoip2-node
node-geoip2
Maxmind GeoIP2 database reader for geolocating ip addresses. Fast native implementation by wrapping libmaxminddb.
salmanh-geoip2-node
Node.js API for GeoIP2 webservice client and database reader
geoip2-lite
MaxMind's GeoIP2 API implementation on Native NodeJS
node-geolite2
This is the pure Node API for reading country and city information from geolite2 database file based on node-maxmind-db
Node.js API for GeoIP2 webservice client and database reader
npm install @maxmind/geoip2-node
Typescript
Module System
Node Version
NPM Version
TypeScript (96.58%)
JavaScript (2.04%)
Shell (1.38%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
Apache-2.0 License
251 Stars
2,217 Commits
23 Forks
17 Watchers
16 Branches
47 Contributors
Updated on Jul 10, 2025
Latest Version
6.1.0
Package Id
@maxmind/geoip2-node@6.1.0
Unpacked Size
66.38 kB
Size
16.99 kB
File Count
43
NPM Version
10.2.3
Node Version
20.10.0
Published on
May 05, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
This package provides a server-side API for the GeoIP2 databases and GeoLite2 databases, and a server-side API for the GeoIP2 web services and GeoLite2 web services.
This package will not work client-side.
1npm install @maxmind/geoip2-node
You can also use yarn
or pnpm
.
IP geolocation is inherently imprecise. Locations are often near the center of the population. Any location provided by a GeoIP2 database or web service should not be used to identify a particular address or household.
To use the web service API, you must create a new WebServiceClient
, using
your MaxMind accountID
and licenseKey
as parameters. The third argument is
an object holding additional option. The timeout
option defaults to 3000
.
The host
option defaults to geoip.maxmind.com
. Set host
to geolite.info
to use the GeoLite2 web service instead of GeoIP2. Set host
to
sandbox.maxmind.com
to use the Sandbox environment.
You may then call the function corresponding to a specific end point, passing it the IP address you want to lookup.
If the request succeeds, the function's Promise will resolve with the model for the end point you called. This model in turn contains multiple records, each of which represents part of the data returned by the web service.
If the request fails, the function's Promise will reject with an error object.
See the API documentation for more details.
1const WebServiceClient = require('@maxmind/geoip2-node').WebServiceClient; 2// Typescript: 3// import { WebServiceClient } from '@maxmind/geoip2-node'; 4 5// To use the GeoLite2 web service instead of the GeoIP2 web service, set 6// the host to geolite.info, e.g.: 7// new WebServiceClient('1234', 'licenseKey', {host: 'geolite.info'}); 8// 9// To use the Sandbox GeoIP2 web service instead of the production GeoIP2 10// web service, set the host to sandbox.maxmind.com, e.g.: 11// new WebServiceClient('1234', 'licenseKey', {host: 'sandbox.maxmind.com'}); 12const client = new WebServiceClient('1234', 'licenseKey'); 13 14client.country('142.1.1.1').then(response => { 15 console.log(response.country.isoCode); // 'CA' 16});
1const WebServiceClient = require('@maxmind/geoip2-node').WebServiceClient; 2// Typescript: 3// import { WebServiceClient } from '@maxmind/geoip2-node'; 4 5// To use the GeoLite2 web service instead of the GeoIP2 web service, set 6// the host to geolite.info, e.g.: 7// new WebServiceClient('1234', 'licenseKey', {host: 'geolite.info'}); 8const client = new WebServiceClient('1234', 'licenseKey'); 9 10client.city('142.1.1.1').then(response => { 11 console.log(response.country.isoCode); // 'CA' 12 console.log(response.postal.code); // 'M5S' 13});
1const WebServiceClient = require('@maxmind/geoip2-node').WebServiceClient; 2// Typescript: 3// import { WebServiceClient } from '@maxmind/geoip2-node'; 4 5// Note that the Insights web service is only supported by the GeoIP2 6// web service, not the GeoLite2 web service. 7// 8// To use the Sandbox GeoIP2 web service instead of the production GeoIP2 9// web service, set the host to sandbox.maxmind.com, e.g.: 10// new WebServiceClient('1234', 'licenseKey', {host: 'sandbox.maxmind.com'}); 11const client = new WebServiceClient('1234', 'licenseKey'); 12 13client.insights('142.1.1.1').then(response => { 14 console.log(response.country.isoCode); // 'CA' 15 console.log(response.postal.code); // 'M5S' 16 console.log(response.traits.userType); // 'school' 17});
For details on the possible errors returned by the web service itself, see the GeoIP2 web service documentation.
If the web service returns an explicit error document, the promise will be rejected with the following object structure:
1{ 2 code: 'THE_ERROR_CODE', 3 error: 'some human readable error', 4 url: 'https://geoip.maxmind.com...', 5}
In addition to the possible errors returned by the web service, the following error codes are provided:
SERVER_ERROR
for 5xx level errorsHTTP_STATUS_CODE_ERROR
for unexpected HTTP status codesINVALID_RESPONSE_BODY
for invalid JSON responses or unparseable response bodiesNETWORK_TIMEOUT
for network request timeoutsFETCH_ERROR
for internal fetch
errorsThe database reader returns a promise that resolves with a reader instance.
You may then call the function corresponding to the request type (e.g.
city
or country
), passing it the IP address you want to look up.
If the request succeeds, the function call will return an object for the GeoIP2 lookup. The object in turn contains multiple record objects, each of which represents part of the data returned by the database.
We use the node-maxmind library as the database reader. As such, you have access to the same options found in that library and can be used like this:
1const Reader = require('@maxmind/geoip2-node').Reader; 2// Typescript: 3// import { Reader } from '@maxmind/geoip2-node'; 4 5const options = { 6 // you can use options like `cache` or `watchForUpdates` 7}; 8 9Reader.open('/usr/local/database.mmdb', options).then(reader => { 10 console.log(reader.country('1.1.1.1')); 11});
If you prefer to use a Buffer
instead of using a Promise
to open the
database, you can use Reader.openBuffer()
. Use cases include:
1const fs = require('fs'); 2const Reader = require('@maxmind/geoip2-node').Reader; 3// Typescript: 4// import { Reader } from '@maxmind/geoip2-node'; 5 6const dbBuffer = fs.readFileSync('/usr/local/city-database.mmdb'); 7const reader = Reader.openBuffer(dbBuffer); 8 9console.log(reader.city('1.1.1.1'));
1const Reader = require('@maxmind/geoip2-node').Reader;
2// Typescript:
3// import { Reader } from '@maxmind/geoip2-node';
4
5Reader.open('/usr/local/share/GeoIP/GeoIP2-Anonymous-IP.mmdb').then(reader => {
6 const response = reader.anonymousIP('85.25.43.84');
7
8 console.log(response.isAnonymous); // true
9 console.log(response.isAnonymousVpn); // false
10 console.log(response.isHostingProvider); // true
11 console.log(response.isPublicProxy); // false
12 console.log(response.isResidentialProxy); // false
13 console.log(response.isTorExitNode); // false
14 console.log(response.ipAddress); // '85.25.43.84'
15});
1const Reader = require('@maxmind/geoip2-node').Reader;
2// Typescript:
3// import { Reader } from '@maxmind/geoip2-node';
4
5Reader.open('/usr/local/share/GeoIP/GeoIP-Anonymous-Plus.mmdb').then(reader => {
6 const response = reader.anonymousPlus('85.25.43.84');
7
8 console.log(response.anonymizerConfidence); // 30
9 console.log(response.isAnonymous); // true
10 console.log(response.isAnonymousVpn); // false
11 console.log(response.isHostingProvider); // true
12 console.log(response.isPublicProxy); // false
13 console.log(response.isResidentialProxy); // false
14 console.log(response.isTorExitNode); // false
15 console.log(response.ipAddress); // '85.25.43.84'
16 console.log(response.networkLastSeen); // '2025-04-14'
17 console.log(response.providerName); // 'FooBar VPN'
18});
1const Reader = require('@maxmind/geoip2-node').Reader; 2// Typescript: 3// import { Reader } from '@maxmind/geoip2-node'; 4 5Reader.open('/usr/local/share/GeoIP/GeoLite2-ASN.mmdb').then(reader => { 6 const response = reader.asn('128.101.101.101'); 7 8 console.log(response.autonomousSystemNumber); // 217 9 console.log(response.autonomousSystemOrganization); // 'University of Minnesota' 10});
1const Reader = require('@maxmind/geoip2-node').Reader; 2// Typescript: 3// import { Reader } from '@maxmind/geoip2-node'; 4 5Reader.open('/usr/local/share/GeoIP/GeoIP2-City.mmdb').then(reader => { 6 const response = reader.city('128.101.101.101'); 7 8 console.log(response.country.isoCode); // 'US' 9 console.log(response.city.names.en); // 'Minneapolis' 10 console.log(response.postal.code); // '55407' 11});
1const Reader = require('@maxmind/geoip2-node').Reader; 2// Typescript: 3// import { Reader } from '@maxmind/geoip2-node'; 4 5Reader.open('/usr/local/share/GeoIP/GeoIP2-Connection-Type.mmdb').then(reader => { 6 const response = reader.connectionType('128.101.101.101'); 7 8 console.log(response.connectionType) // 'Cable/DSL' 9 console.log(response.ipAddress) // '128.101.101.101' 10});
1const Reader = require('@maxmind/geoip2-node').Reader; 2// Typescript: 3// import { Reader } from '@maxmind/geoip2-node'; 4 5Reader.open('/usr/local/share/GeoIP/GeoIP2-Country.mmdb').then(reader => { 6 const response = reader.country('128.101.101.101'); 7 8 console.log(response.country.isoCode); // 'US' 9});
1const Reader = require('@maxmind/geoip2-node').Reader; 2// Typescript: 3// import { Reader } from '@maxmind/geoip2-node'; 4 5Reader.open('/usr/local/share/GeoIP/GeoIP2-Domain.mmdb').then(reader => { 6 const response = reader.domain('128.101.101.101'); 7 8 console.log(response.domain) // 'umn.edu' 9 console.log(response.ipAddress) // '128.101.101.101' 10});
1const Reader = require('@maxmind/geoip2-node').Reader; 2// Typescript: 3// import { Reader } from '@maxmind/geoip2-node'; 4 5Reader.open('/usr/local/share/GeoIP/GeoIP2-Enterprise.mmdb').then(reader => { 6 const response = reader.enterprise('128.101.101.101'); 7 8 console.log(response.country.isoCode) // 'US' 9});
1const Reader = require('@maxmind/geoip2-node').Reader; 2// Typescript: 3// import { Reader } from '@maxmind/geoip2-node'; 4 5Reader.open('/usr/local/share/GeoIP/GeoIP2-ISP.mmdb').then(reader => { 6 const response = reader.isp('128.101.101.101'); 7 8 console.log(response.autonomousSystemNumber); // 217 9 console.log(response.autonomousSystemOrganization); // 'University of Minnesota' 10 console.log(response.isp); // 'University of Minnesota' 11 console.log(response.organization); // 'University of Minnesota' 12 13 console.log(response.ipAddress); // '128.101.101.101' 14});
If the database file does not exist, is not readable, is invalid, or there is a bug
in the reader, the promise will be rejected with an Error
with a message
explaining the issue.
If the database file and the reader method do not match (e.g.
reader.city
is used with a Country database), a BadMethodCalledError
will
be thrown.
If the IP address is not found in the database, an AddressNotFoundError
will
be thrown.
If the IP address is not valid, a ValueError
will be thrown.
If the database buffer is not a valid database, an InvalidDbBufferError
will
be thrown.
We strongly discourage you from using a value from any names
property as a
key in a database or object.
These names may change between releases. Instead we recommend using one of the following:
city.geonameId
continent.code
or continent.geonameId
country.isoCode
or country.geonameId
subdivision.isoCode
or subdivision.geonameId
While many of the models contain the same basic records, the attributes which can be populated vary between web service end points or databases. In addition, while a model may offer a particular piece of data, MaxMind does not always have every piece of data for any given IP address.
Because of these factors, it is possible for any request to return a record where some or all of the attributes are unpopulated.
The only piece of data which is always returned is the ipAddress
attribute in
the geoip2-node.TraitsRecord
record.
GeoNames offers web services and downloadable
databases with data on geographical features around the world, including
populated places. They offer both free and paid premium data. Each feature
is uniquely identified by a geonameId
, which is an integer.
Many of the records returned by the GeoIP web services and databases include a
geonameId
field. This is the ID of a geographical feature (city, region,
country, etc.) in the GeoNames database.
Some of the data that MaxMind provides is also sourced from GeoNames. We source things like place names, ISO codes, and other similar data from the GeoNames premium data set.
If the problem you find is that an IP address is incorrectly mapped, please submit your correction to MaxMind.
If you find some other sort of mistake, like an incorrect spelling, please check the GeoNames site first. Once you've searched for a place and found it on the GeoNames map view, there are a number of links you can use to correct data ("move", "edit", "alternate names", etc.). Once the correction is part of the GeoNames data set, it will be automatically incorporated into future MaxMind releases.
If you are a paying MaxMind customer and you're not sure where to submit a correction, please contact MaxMind support for help.
MaxMind has tested this API with Node.js versions 18, 20, and 22. We aim to support active and maintained LTS versions of Node.js.
Patches and pull requests are encouraged. Please include unit tests whenever possible, as we strive to maintain 100% code coverage.
The GeoIP2 Node.js API uses Semantic Versioning.
Please report all issues with this code using the GitHub issue tracker
If you are having an issue with a MaxMind service that is not specific to the client API, please contact MaxMind support for assistance.
This software is Copyright (c) 2018-2025 by MaxMind, Inc.
This is free software, licensed under the Apache License, Version 2.0.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
all changesets reviewed
Reason
30 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
SAST tool is run on all commits
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
1 existing vulnerabilities detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 6
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More