Coder Social home page Coder Social logo

atlanteh / node-geolite2-redist Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gitsquared/node-geolite2-redist

0.0 0.0 0.0 39.88 MB

Redistribution of MaxMind GeoLite2 GeoIP databases as an npm library

Home Page: https://gitsquared.github.io/node-geolite2-redist/

License: Other

JavaScript 0.40% Shell 24.97% TypeScript 74.63%

node-geolite2-redist's Introduction

node-geolite2-redist

Automatic Redistribution Updates NPM published version Node version Types Status


MaxMind's GeoLite2 free databases as an npm library. As this is a redistribution, you don't need a MaxMind license key. However, some additional legal restrictions apply, make sure to read this README and the Legal Warning carefully before deciding to use this.

You will need a database reader capable of reading .mmdb files, like node-maxmind, if you wish to use the data.

This package is compatible with the 3 GeoLite2 databases, namely:

  • GeoLite2-ASN
  • GeoLite2-Country
  • GeoLite2-City

For more info check out the MaxMind website.

Due to license requirements, this package automatically updates the databases in the background when it detects that a new version is available. This should be transparent for most usecases, if you're experiencing any problem with it, please file an issue.

See Legal Warning section for more info on licensing and limitations.

Usage

Installing

npm install geolite2-redist

Using the geoip data

Example geoip lookup in a Node environment, using the GeoLite2-City database with node-maxmind as a db reader:

Javascript

const maxmind = require('maxmind');

// This module is distributed as en ESM module (import...from... syntax), but you can
// use an import() promise to make it work without switching to ESM!
import('geolite2-redist').then((geolite2) => {
 return geolite2.open(
  'GeoLite2-City',                 // database name
  (dbPath) => maxmind.open(dbPath) // function that builds a useful db reader
  )
}).then((reader) => {
  const lookup = reader.get('185.194.81.29')

  console.log(lookup.country.iso_code) // FR ๐Ÿฅ–๐Ÿ‡ซ๐Ÿ‡ท

  // Calling close() here shuts everything down nicely and clears up Node's event loop.
  reader.close()
})

Typescript

import geolite2, { GeoIpDbName } from 'geolite2-redist';
import maxmind, { CountryResponse } from 'maxmind';

(async () => {
  const reader = await geolite2.open(
    GeoIpDbName.Country, // Use the enum instead of a string!
    (path) => maxmind.open<CountryResponse>(path)
  )

  const lookup = reader.get('185.194.81.29')

  console.log(lookup.country.iso_code) // FR ๐Ÿฅ–๐Ÿ‡ซ๐Ÿ‡ท

  reader.close()
})();

Preloading databases

You can add this to your package.json to preload the databases after running npm install, instead of downloading them the first time open is called:

{
  "scripts": {
    "preload": "node -e \"import('geolite2-redist').then(geolite => geolite.downloadDbs())\""
  }
}

API

You can find a more detailed documentation on the Typedoc-generated website.

Legal Warning

Privacy regulations (CCPA in California, GDPR in Europe) that implement the right-to-forget have affected MaxMind's EULA & licenses. In a nutshell, you should always make sure your GeoIP databases are up to date, which this library conveniently does for you ;)

That said, please carefully read the LICENSE and EULA files. The databases are provided under certain restrictions and obligations, most notably:

  • You cannot prevent the library from updating the databases.
  • You cannot use the GeoLite2 data:
    • for FCRA purposes in the USA,
    • to identify specific households or individuals, worldwide.

If you plan on using node-geolite2 behind a firewall, you need to whitelist the GitHub IP range so that the package can reach the databases mirror.

Compatibility

We follow the OpenJS Foundation's deprecation schedule and support all maintained Node versions.

Alternatives

If you do have a MaxMind license key (which you can get by signing up here), you might prefer using node-geolite2, which this repository is originally a fork of.

License

The databases themselves are provided by MaxMind under CC BY-SA 4.0

For the library, see LICENSE.


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

node-geolite2-redist's People

Contributors

anandchowdhary avatar baleevskiy avatar dependabot[bot] avatar gitsquared avatar neilstuartcraig avatar realdolos avatar rhoggs-bot-test-account avatar runk avatar sbma44 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.