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

ipstackgeo-js

v2.0.1

Published

A simple library used to interface with an IPStack Geo API.

Downloads

8

Readme

IPStack for Node.JS (Geo Location Library)

IPStack for Node.JS is a simple library used to interface with an IPStack Geo API.

$ npm i ipstackgeo-js

Sponsor Me! Downloads GitHub stars GitHub issues GitHub license

Learn more about IPStack here: ipstack.net

Looking for the Python version?

Looking for the PHP version?

Features

  • Retrieve the Geo Location data for any IP address.
  • Retrieve the Geo Location data for the system executing this code.
  • Retrieve the Geo Location data for a client.
  • Retrieve the Geo Location data for a batch of IP addresses.
  • Assess the security of an IP address.

Basic Usage

const geoLookup = require(`ipstackgeo-js`)('<YOUR-API-KEY>');

geoLookup.forSelf().then(
    res => console.log(res),
    err => console.log(err)
);

Example Usage

Note: See IPStack: Response Objects for a list of available properties in a response object.

Create the GeoLookup Object

const geoLookup = require(`ipstackgeo-js`)('<YOUR-API-KEY>');

Lookup a location for an IP Address

// Retrieve the location information for 
// github.com by using it's hostname.
// 
// This function will work with hostnames
// or IP addresses.
geoLookup.forIps('github.com')
    .then(
        (res) => console.log(res),
        (err) => console.log(err)
    );

Look up own location

geoLookup.forSelf().then(
    (res) => console.log(res),
    (err) => console.log(err)
);

Other Features

There are also a few other useful features built into this library and the IPStack API.

  1. Bulk Location Lookup

    The ipstack API also offers the ability to request data for multiple IPv4 or IPv6 addresses at the same time. This requires the PROFESSIONAL teir API key or higher and is limitted to 50 IPs at a time.

    See: https://ipstack.com/documentation#bulk

    const ips = ['google.com', 'github.com', '1.1.1.1'];
    geoLookup.forIps(...ips).then(
        (res) => console.log(res),
        (err) => console.log(err)
    );
  2. Requesting the hostname for an IP address.

    By default, the ipstack API does not return information about the hostname the given IP address resolves to. In order to include the hostname use the following.

    See: https://ipstack.com/documentation#hostname

    geoLookup.forIps('1.1.1.1')
        .lookupHostname()
        .then(
            (res) => console.log(res.hostname),
            (err) => console.log(err)
        );

    Output:

    one.one.one.one
  3. Assessing Security

    Customers subscribed to the Professional Plus Plan may access the ipstack API's Security Module, which can be used to assess risks and threats originating from certain IP addresses before any harm can be done to a website or web application.

    See: https://ipstack.com/documentation#security

    geoLookup.forIps('1.1.1.1')
        .assessSecurity()
        .then(
            (res) => console.log(res),
            (err) => console.log(err)
        );
  4. Set the language for a response

    The ipstack API is capable of delivering its result set in different languages. To request data in a language other than English (default) use following with one of the supported language codes.

    See: https://ipstack.com/documentation#language

    Supported Langauges

    geoLookup.forSelf()
        .language('en')
        .then(
            (res) => console.log(res),
            (err) => console.log(err)
        );
  5. Configuring your request

    geoLookup.forSelf()
        /// Use HTTPS. Note: This requires IPStack Basic plan or higher.
        .useHttps()
        /// Configure the timeout for requests
        .timeout(15000)
        .then(
            (res) => console.log(res),
            (err) => console.log(err)
        );
  6. Using JSONP Callbacks

    The ipstack API supports JSONP Callbacks, enabling you to enter a function name and cause the API to return your requested API result wrapped inside that function.

    See: https://ipstack.com/documentation#jsonp

    geoLookup.forIp()
        .jsonp('someSpecialFunctionName')
        .then(
            // When using jsonp(), res will be a string instead of an object.
            (res) => console.log(res),
            (err) => console.log(err)
        );

    Output:

    someSpecialFunctionName({ ... });