NOTE: A better, faster, more in-depth IP geocoder for node.js called GeoIP -- inspired by this project -- is now available from Kuno. I would recommend using that library.
###FAQ
What is it?
GeoIP.js is a simple, three method class that allows you to enter an IP address and get back a latitude/longitude.
How does it work?
GeoIP.js works by providing v8->C++ glue code that interfaces with the free MaxMind geocoding library.
-
Download the MaxMind C API from here.
-
Install the MaxMind C API:
wget http://geolite.maxmind.com/download/geoip/api/c/GeoIP-1.4.6.tar.gz
tar -xvzf GeoIP-1.4.6.tar.gz cd GeoIP-1.4.6 ./configure make sudo make install
Note: 'sudo make install' also installs a few command line programs: geoiplookup, geoiplookup6, and geoipupdate. You probably don't want them. To remove them, just delete them from '/usr/local/bin/'.
- Download this project and build it:
git clone [email protected]:joevennix/GeoIP-js.git
cd GeoIP-js node-waf configure build
-
Download the MaxMind Geocoding Database file, GeoLiteCity.dat.gz. Un-gzip this file and stick it where ever you want.
-
That's it! Let's look at some code:
var geo = require('./GeoIP-js/geoip.js');
geo.open({ cache: true, filename: './geoip/GeoLiteCity.dat'}); var coord = geo.lookup('74.125.227.16'); console.log(coord); geo.close(); You should see the ouput:
$ node test.js [ 37.4192008972168, -122.05740356445312 ] $