Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 72 lines (47 sloc) 2.75 kb

GeoIP API for node.


Get geolocation information based on domain or IP address.


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

There are two 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


npm install geoip


Country Information

  • Open the country data file

    var 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' });

  • Set all properties of an existing data object to undefined. geoip.close(data);

City Information

  • Open the GeoLiteCity.dat file first.

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

    geoip.City.record_by_addr(data, ''); // You will get something like this:

                                                    //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 
Something went wrong with that request. Please try again.