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

ipdata

v2.2.4

Published

JavaScript library to gather information for an ip using https://ipdata.co.

Downloads

34,154

Readme

IPData JavaScript Library

JavaScript library that can be used in a web browser or Node.js application to gather information for an IP address using https://ipdata.co.

Table of Contents

Install

$ npm install ipdata

Use

Import library

Import the library.

import IPData from 'ipdata';

Note: If you are using require() then you will need to use the default value exported from the library.

const IPData = require('ipdata').default;

Create an Instance

Create an instance of the IPData class and pass your api key for IPData as the first parameter.

const ipdata = new IPData('<apiKey>');

The library will cache 4096 ip addresses responses for 24 hours using a LRU cache by default. You can configure the cache by passing an object as the second paramenter.

const cacheConfig = {
  max: 1000, // max size
  maxAge: 10 * 60 * 1000, // max age in ms (i.e. 10 minutes)
};
const ipdata = new IPData('<apiKey>', cacheConfig);

Note: To disable the cache pass -1 as the maxAge.

const cacheConfig = {
  maxAge: -1, // disable the cache
};
const ipdata = new IPData('<apiKey>', cacheConfig);

Lookup

The library will lookup the ip address of the host computer if no ip address is provided.

ipdata.lookup()
  .then(function(info) {
    // info.ip === '<hostcomputerip>'
    // ...
  });

You can pass an ip address as the first parameter to the lookup() method to lookup information about the ip address using IPData.

const ip = '1.1.1.1';
ipdata.lookup(ip)
  .then(function(info) {
    // info.ip === 1.1.1.1
    // ...
  });

You can specify only a select field to be returned when looking up an ip address by passing a field as the second parameter to the lookup() method.

const ip = '1.1.1.1';
const selectField = 'ip';
ipdata.lookup(ip, selectField)
  .then(function(info) {
    // info.select_field === 1.1.1.1
    // ...
  });

You can specify only certain fields to be returned when looking up an ip address by passing an array of fields as the third parameter to the lookup() method.

const ip = '1.1.1.1';
const fields = ['ip', 'city'];
ipdata.lookup(ip, null, fields)
  .then(function(info) {
    // ...
  });

Bulk Lookup

You can lookup multiple ip addresses with one API call using the bulkLookup() method.

const ips = ['1.1.1.1', '1.0.0.1'];
ipdata.bulkLookup(ips)
  .then(function(info) {
    // info[0].ip === 1.1.1.1
    // ...
  });

You can specify only certain fields to be returned when looking up multiple ip addresses by passing an array of fields as the second parameter to the bulkLookup() method.

const ips = ['1.1.1.1', '1.0.0.1'];
const fields = ['ip', 'city'];
ipdata.bulkLookup(ips, fields)
  .then(function(info) {
    // ...
  });