Skip to content

Node.js module for automatic update of free maxmind geoip database

License

Notifications You must be signed in to change notification settings

vetraz/node-freeMaxDev-updater

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

node-freeMaxMind-updater

Javascript module for updating free Geo IP Maxmind binary databases (aka mmdb or geoip2). Based on Node.js EventEmitter, so that it can be combined with other Maxmind based modules.

GEO databases

Free GEO databases are available for download here.

Installation

npm i fmaxmind-updater

Usage

var ipDatabaseUpdater = require('fmaxmind-updater');

var ipDbUpdater = new ipDatabaseUpdater({
  destFile: '/tmp/GeoLite2-Country.mmdb.gz',
  md5url: 'http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.md5',
  originFile: '/dbWillBeHere/GeoLite2-Country.mmdb',
  timeout: 24*60*60*1000,
  url: 'http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.mmdb.gz'
});

ipDbUpdater.on('error', function(data){ console.log(new Date(), data) });
ipDbUpdater.on('notice', function(data){ console.log(new Date(), data) });
ipDbUpdater.on('update', function(data){ console.log(new Date(), data) }); //reload maxmind plugin on this event

ipDbUpdater.start();

Methods

.start()

Initially get server hash which triggers all update process. Also set timeout to repeat this process.

var ipDatabaseUpdater = require('fmaxmind-updater');
var ipDbUpdater = new ipDatabaseUpdater();
ipDbUpdater.start();

.stop()

Clears timeout, i.e. prevents next server hash checking.

...
ipDbUpdater.stop();

Events

Emits following events:

  • error
  • notice
  • update

error

Triggered when error occurs

var ipDatabaseUpdater = require('fmaxmind-updater');
var ipDbUpdater = new ipDatabaseUpdater();

ipDbUpdater.on('error', function(data){ console.log(new Date(), data) });

notice

Triggered when plugin has been started, stopped or database is up to date

var ipDatabaseUpdater = require('fmaxmind-updater');
var ipDbUpdater = new ipDatabaseUpdater();

ipDbUpdater.on('notice', function(data){ console.log(new Date(), data) });

update

Triggered when database has been updated

var ipDatabaseUpdater = require('fmaxmind-updater');
var ipDbUpdater = new ipDatabaseUpdater();

ipDbUpdater.on('update', function(data){ console.log(new Date(), data) });

Options

destFile

Temporary file location which is used for downloading from server. Should have .gz extension.

var ipDbUpdater = new ipDatabaseUpdater({
  ...
  destFile: '/tmp/GeoLite2-Country.mmdb.gz',
  ...
});

md5url

Url for obtaining database md5 hash from maxmind server.

var ipDbUpdater = new ipDatabaseUpdater({
  ...
  destFile: '/tmp/GeoLite2-Country.mmdb.gz',
  ... 
});

originFile

Path to file to be updated.

var ipDbUpdater = new ipDatabaseUpdater({
  ...
  originFile: '/dbWillBeHere/GeoLite2-Country.mmdb',
  ... 
});

timeout

Checks for updates every 'timeout' milliseconds.

var ipDbUpdater = new ipDatabaseUpdater({
  ...
  timeout: 24*60*60*1000,
  ... 
});

url

Url of gziped free database.

var ipDbUpdater = new ipDatabaseUpdater({
  ...
  url: 'http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.mmdb.gz',
  ... 
});

Dependencies

md5-file by linusu github repo

License

MIT

About

Node.js module for automatic update of free maxmind geoip database

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published