Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@streamr/geoip-location

streamr-dev985Apache-2.0103.0.0TypeScript support: included

Library for getting location information from IP addresses based on MaxMind GeoLite2 databases

readme

geoip-location

@streamr/geoip-location is a package that provides a way to detect the latitude and longitude of an IP address using the mmdb-lib reader package and the MaxMind GeoLite2 City database resdistributed by GitSquared/node-geolite2-redist. The library complies with the [MaxMind GeoLite2 End User License Agreement] (https://www.maxmind.com/en/geolite2/eula) by keeping the database up-to-date by periodically downloading the fresh database from the GitSquared/node-geolite2-redist repository.

Differences to the node-geolite2-redist package

  • The period between checks for the updates of the GeoLite2 City database is configurable
  • Distributed as commonjs module for greater compatibility with other packages
  • Better error handling and focus on clean shutdown without lingering timers or memory leaks
  • Fewer dependencies: uses 'fetch' instead of 'got' for downloading the database
  • Only supports the GeoLite2 City database
  • Only returns the latitude and longitude of the IP address

Getting started

Installation

npm install @streamr/geoip-location

Usage

import { GeoIpLocator } from '@streamr/geoip-location'

(async () => {

        // Creates a new GeoIpLocator object with the following parameters:
        // geoiIpDatabasePath: string - the path to the directory for the GeoLite2 City database
        // the disrectory will be created if it does not exist. 
        // dbCheckInterval?: number - the interval in milliseconds between the checks 
        // for the updates of the GeoLite2 City database (default: 28 days)
        // dbCheckErrorInterval?: number - the interval in milliseconds between the checks 
        // for the updates of the GeoLite2 City database in case of a failed update (default: 1 day)

        const locator = new GeoIpLocator('~/geoipdatabases', 15 * 24 * 60 * 60 * 1000, 60 * 60 * 1000)

        // Downloads the GeoLite2 City database if it is not found in the geoiIpDatabasePath 
        // or if the database is outdated. Also starts the db update timer. 

        await locator.start()

        // Returns the { latitude, longitude } of the IP address 
        // or undefined if the location cannot be found

        const location = locator!.lookup('62.241.198.245')

        console.log(location.latitude)         // 60.1695
        console.log(location.longitude)        // 24.9354

        // Stops the db update timer, does not delete the GeoLite2 City database

        locator.stop()

        // (optional) Deletes the GeoLite2 City database

        fs.unlinkSync(dbDir + '~/geoipdatabases/GeoLite2-City.mmdb')

})()

License

This package is licensed under the Apache-2.0 license (see LICENSE). The databases themselves are provided by MaxMind under CC BY-SA 4.0 and redistributed by GitSquared/node-geolite2-redist

This software package uses GeoLite2 data created by MaxMind, available from https://www.maxmind.com.

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

Changes before Tatum release are not documented in this file.

Unreleased

@streamr/sdk

Added

Changed

Deprecated

Removed

Fixed

Security

@streamr/node

Added

Changed

Deprecated

Removed

Fixed

Security

@streamr/cli-tools

Added

Changed

Deprecated

Removed

Fixed

Security

103.0.0 - 2025-06-10

@streamr/sdk

Added

Changed

Deprecated

Removed

Fixed

@streamr/node

Added

Changed

@streamr/cli-tools

Added

Changed

102.1.1 - 2025-04-29

@streamr/sdk

Changed

  • Update internal list of JSON RPC urls for Polygon

102.1.0 - 2025-02-19

@streamr/node

Fixed

@streamr/cli-tools

Added

102.0.0 - 2025-01-27

@streamr/sdk

Added

Changed

Removed

Fixed

@streamr/node

Added

Changed

Removed

Fixed

@streamr/cli-tools

Added

Changed

101.1.2 - 2024-09-04

@streamr/sdk

Fixed

101.1.1 - 2024-08-29

@streamr/sdk

Changed

@streamr/node

Changed

Fixed

101.1.0 - 2024-08-13

@streamr/sdk

Added

Fixed

@streamr/node

Added

Fixed

101.0.1 - 2024-07-09

@streamr/sdk

Changed

101.0.0 - 2024-07-08

@streamr/sdk

Changed

Removed

@streamr/node

Changed

Deprecated

Fixed

100.2.4 - 2024-05-06

@streamr/sdk

Added

Fixed

@streamr/node

Added

@streamr/cli-tools

Removed

100.2.3 - 2024-04-15

@streamr/sdk

Fixed

100.2.2 - 2024-04-03

@streamr/sdk

Changed

  • Update internal list of JSON RPC urls for Polygon

100.2.1 - 2024-04-02

@streamr/sdk

Added

Changed

Fixed

@streamr/node

Changed

100.2.0 - 2024-03-28

@streamr/sdk

Added

100.1.2 - 2024-03-27

@streamr/sdk

Fixed

  • Update internal list of JSON RPC urls for Mumbai testnet

100.1.1 - 2024-03-26

@streamr/sdk

Fixed

  • Update internal list of JSON RPC urls for Polygon

100.1.0 - 2024-03-25

@streamr/sdk

Added

Changed