npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ip-geolocate

v1.0.1

Published

This module uses freegeoip.net to attempt to determine geolocation based on IP address.

Downloads

277

Readme

Overview

Use freegeoip.net to get geolocation information based on IP address.

If you like the freegeoip.net service (it's an awesome free service), please consider donating to it. See http://freegeoip.net/ for more information.

Note that freegeoip.net allows up to 10,000 queries per hour. Once this limit is reached, all of your requests will result in errors until your quota is cleared at the end of the hour.

Install

npm install ip-geolocate --save

Usage

The getLocation method requires an IP address (as a string) and a callback. Note that the method will check for IP address validity and that both IPv4 and IPv6 IP addresses are supported.

var geolocate = require('ip-geolocate');

var ip = '127.0.0.1';

geolocate.getLocation(ip, function(err, location) {
    if(err) {
        // Error occurred, latency threshold hit, or IP address is invalid
        console.log(err);
    }
    else {
        // Success
       console.log(location);
    }
});

Optional Options Argument

You can (optionally) pass an options object as the second argument.

  • maxLatency: By default, the max time to wait for a response from freegeoip.net service is 2000 milliseconds. Change this to whatever you want.
  • serviceUrl: By default the serviceUrl is set to "http://freegeoip.net/json/". However, you may decide to install your own service on your own servers if the 10,000 request limit is too restrictive (see freegeoip.net documentation for more info). If so, include the URL of your service here, including the protocol (e.g., http://) and trailing slash.

Example

var geolocate = require('ip-geolocate');

var ip = '127.0.0.1';
var options = {
    maxLatency : 5000,
    serviceUrl : 'http://alternetfreegeoip.net/json/'
}

geolocate.getLocation(ip, options, function(err, location) {
    if(err) {
        console.log(err);
    }
    else {
       console.log(location);
    }
});

Response

The method will return a location object in the callback that will look something like this:

{
    ip: '127.0.0.1',
    country_code: 'US',
    country_name: 'United States',
    region_code: 'CA',
    region_name: 'California',
    city: 'San Mateo',
    zip_code: '94403',
    time_zone: 'AmericaLos_Angeles',
    latitude: 37.5402,
    longitude: -122.3041,
    metro_code: 807
}