Skip to content

lookupCountry

reference
1 min readUpdated

Kind: Function

Source: atloria-monorepo/apps/api/src/analytics/utils/tracking-utils.ts

Resolve a client IP to a 2-letter ISO country code using the bundled MaxMind GeoLite2 database (via geoip-lite). This is the same approach Umami, Plausible, and Matomo all use for server-side geolocation.

Returns null for:

  • localhost / private IPs (127., 10., 192.168.*, etc.)
  • IPs not found in the database
  • malformed inputs

The GeoLite2 database is loaded into RAM once at startup (~2MB). All subsequent lookups are pure memory reads — sub-microsecond latency.

Signature

ts
function lookupCountry(ip: string | null): string | null

Parameters

NameType
ip`string

Returns: string | null

Was this page helpful?

Download as PDF