Understand data availability and unpopulated attributes
mainipAddress within the geoip2-node.TraitsRecord record.repository·main·Indexed 42 days ago
https://github.com/maxmind/geoip2-nodeA Node.js API for performing IP geolocation lookups using MaxMind's GeoIP and GeoLite databases locally via the Reader class or remotely through the WebServiceClient. Version 7.1.0 supports local .mmdb files and web service endpoints for country, city, and insights data.
ipAddress within the geoip2-node.TraitsRecord record.geonameId field. This field is an integer representing the unique identifier for a geographical feature (such as a city, region, or country) in the GeoNames database.The following platforms are supported for development:
Note: Intel macOS and Windows ARM64 are not supported. Specifically, Intel macOS cannot be used because pnpm 11.0.5 and later do not ship a darwin-x64 binary, preventing mise from installing necessary tools.
Do not use values from names properties as keys in your own databases or objects, as these names may change between releases. Instead, use these stable identifiers:
city.geonameIdcontinent.code or continent.geonameIdcountry.isoCode or country.geonameIdsubdivision.isoCode or subdivision.geonameIdInstall the package using npm, yarn, or pnpm to access MaxMind GeoIP and GeoLite databases and web services in a server-side Node.js environment. Note that this package is not intended for client-side use.
npm install @maxmind/geoip2-nodeThis project uses pnpm for dependency management and mise for tool versioning. The repository is a pnpm workspace, so do not use npm or corepack, as they cannot resolve workspace:* dependencies used in the workspace members (e2e/js and e2e/ts).
To set up the environment:
mise using mise install.pnpm install.mise install
pnpm installPrecious is used to tidy and lint the codebase. You can set it up locally and configure a pre-commit hook to automate the process.
mkdir -p local && ./bin/install-precious local./git/setup.shmkdir -p local && ./bin/install-precious local
./git/setup.shTo use the web service API, instantiate a WebServiceClient with your MaxMind accountID and licenseKey. You can then call specific endpoint methods (like country, city, or insights) passing an IP address. These methods return a Promise that resolves to a model containing multiple records.
When instantiating WebServiceClient, you can pass an options object as the third argument:
timeout: Request timeout in milliseconds (defaults to 3000).host: The API endpoint host.geoip.maxmind.com (default for GeoIP)geolite.info (for GeoLite web service)sandbox.maxmind.com (for the Sandbox environment)fetcher: A custom fetch implementation (defaults to the global fetch).import { WebServiceClient } from '@maxmind/geoip2-node';
// Example: Using the Country Service
const client = new WebServiceClient('1234', 'licenseKey');
client.country('142.1.1.1').then(response => {
console.log(response.country.isoCode); // 'CA'
});To use local .mmdb database files, use the Reader class. You can open a database file via a path or use a Buffer for synchronous operations or external data sources.
Reader.open(path, options) returns a Promise that resolves to a reader instance. The options object supports features from the node-maxmind library, such as cache or watchForUpdates.
Reader.openBuffer(buffer) allows you to use a pre-loaded Buffer. This is useful for synchronous workflows or when the database is fetched from an external source.
import { Reader } from '@maxmind/geoip2-node';
// Using a file path
Reader.open('/usr/local/database.mmdb', { cache: true }).then(reader => {
console.log(reader.country('1.1.1.1'));
});
// Using a Buffer
import { readFileSync } from 'node:fs';
const dbBuffer = readFileSync('/usr/local/city-database.mmdb');
const reader = Reader.openBuffer(dbBuffer);
console.log(reader.city('1.1.1.1'));If you encounter data issues, follow these steps based on the type of error:
Many records in the MaxMind API (such as CityRecord, ContinentRecord, RegisteredCountryRecord, and SubdivisionsRecord) include a names object. This object provides the name of a place in various supported locales.
Important: Do not use these localized names as keys for databases or dictionaries. Always use the provided geonameId or relevant ISO codes for programmatic lookups or storage.
export interface Names {
readonly de?: string;
readonly en: string;
readonly es?: string;
readonly fr?: string;
readonly ja?: string;
readonly 'pt-BR'?: string;
readonly ru?: string;
readonly 'zh-CN'?: string;
}