Maxmind GeoIP Stream
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
test
.gitignore
Gruntfile.js
LICENSE
README.md
index.js
package.json

README.md

geoip-stream

Maxmind GeoIP Stream. Transforms a JSON string stream of objects by looking for an ip field (as defined) and appending maxmind data to the stream if it is found. Uses readable-stream for node < 0.10 to ensure stream2+ sanity.

Install

npm install geoip-stream

Maxmind data installed, ex: free Maxmind GeoLiteCity stored in ./GeoLiteCity.dat

Usage

Sample logfile.json line:

{"ip": "198.55.125.23", "timestamp":"2014-02-24 10:29:42", "url": "http:\/\/somedomain.com"}
var fs          = require('fs');
var logstream   = fs.createReadStream('logfile.json');
var split       = new require('split')();
var geoipStream = require('geoip-stream');
var geoip       = new geoipStream({
	dataPath:        './GeoLiteCity.dat', // default
	memoryCache:     true,                // default
	checkForUpdates: true,                // default
	ipField:         'ip',                // default
	dropIpField:     true                 // default is false
});

logstream
.pipe(split)
.pipe(geoip)
.pipe(process.stdout) // { "timestamp": ..., "countryCode": "US", "city":"Dallas", ...}

License

MIT