npm.io
0.2.12 • Published 12 years ago

geoip-stream

Licence
MIT
Version
0.2.12
Deps
3
Vulns
0
Weekly
0
Stars
1

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