Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

182 lines (108 sloc) 4.675 kb

GeoIP API for node.

Emergent Update

Warning: Due to the Asynchronous programming problome,

Any version that below the 0.1.3 dosen't work in any real script.

I highly recommond that every user should update to at least v0.1.3!


Get geolocation information based on domain or IP address.




v0.1.0, 2010-11-25

1, Initial release;

v0.1.1, 2010-11-27:

1, Removed GeoIP.dat, due to licence(or money) problem.

2, renamed city property to City, renamed country property to Country.

3, Allow close method to set all properties of an exsiting obj to undefined.

v0.1.2, 2010-12-02:

1, Fixed missing of isIP method in node 0.2.x series.

2, Hidden some unsafe an useless funcions.

v0.2.0, 2010-12-09:

1, added org, region, netspeed submodule.

2, added data type check in every submodule

3, re-factoring whloe project.

v0.2.1, 2010-12-10:

1, added support for GeoIPASNum.dat binary data.

2, make org_by_addr return an array of org name string.


Befor you can use this package, you need to download or buy some data from

There are three free versions data among with some commercial versions.

Note: This package only support binary data, not any other formats.

GeoIP Country Lite Edition Download.

GeoIP City Lite Edition Download

GeoIP ASN Edition download


npm install geoip


Country Information

  • Open the country data file

    var country_data ='/path/to/GeoIP.dat');

  • Synchronous methods, network independence.

    geoip.Country.code_by_addr(data, ''); // prints 'US'

    geoip.Country.name_by_addr(data, ''); // prints 'United States'

  • Asynchronous methods, depends on node's async-style dns module.

    geoip.Country.code_by_domain(data, '', function(err, code) { if (err) {throw err;} console.log(code); // prints 'US' });

    geoip.Country.name_by_domain(data, '', function(err, name) { if (err) {throw err;} console.log(name); // prints 'United States' });

    //Close the opened file. geoip.close(data);

City Information

  • Open the GeoLiteCity.dat file first.

    var city_data ='/path/to/GeoLiteCity.dat');

    geoip.City.record_by_addr(data, ''); // Return an object of city information //'{ // "country_code":"US", // "country_code3":"USA", // "country_name":"United States", // "continet_code":"NA", // "region":"CA", // "city":"Mountain View", // "postal_code":"94043", // "latitude":37.41919999999999, // "longitude":-122.0574, // "dma_code":807, // "metro_code":807, // "area_code":650 // }'


Organization Information

  • Get Organization Information

    //Open the GeoIPOrg.dat first. var org_data ='/path/to/GeoIPOrg.dat');

    geoip.Org.org_by_addr(org_data, ''); // Return an array of the names of organization // [ // 'Genuity', // 'The United Way', // 'Education Management Corporation, // 'International Generating Co. (Intergen)' // ]


  • Get ASN informatioin

    //Open the GeoIPASNum.dat first.

    var asn_data ='/path/to/GeoIPASNum.dat');

    geoip.Org.asn_by_addr(asn_data, ''); // Return an array of asn objects //[ // { number: 'AS15169', description: 'Google Inc.' }, // { number: 'AS36597', // description: 'OmniTI Computer Consulting Inc.' }, // { number: 'AS26471', // description: 'Smart City Networks' } //]

Region Information

  • Open the GeoIPRegion.dat first.

    var region_data ='/path/to/GeoIPRegion.dat');

    geoip.Region.region_by_addr(region_data, ''); // prints 'US,CO'


NetSpeed Information

  • Open the GeoIPNetSpeed.dat first.

    var netspeed_data ='/path/to/GeoIPNetSpeed.dat');

    geoip.NetSpeed.speed_by_addr(netspeed_data, ''); // prints 'Dailup'


Jump to Line
Something went wrong with that request. Please try again.