IPData JavaScript Library
JavaScript library that can be used in a web browser or Node.js application to gather information using https://ipdata.co.
Table of Contents
Install
$ npm install ipdata
Import the library
Import the library.
import ipdata from 'ipdata';
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 responses using the lookup()
method for 24 hours using a LRU cache. You can turn off the cache by passing false
as the second parameter to the constructor.
const ipdata = new IPData('<apiKey>', false);
Lookup
The library will lookup the ip address of the host computer if no ip address is provided.
ipdata.lookup()
.then(function(info) {
});
You can pass an ip address as the first parameter to the lookup()
method to lookup information about the ip address using IPData.
ipdata.lookup('1.1.1.1')
.then(function(info) {
});
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) {
});
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.
ipdata.bulkLookup(['1.1.1.1', '1.0.0.1'])
.then(function(info) {
});
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) {
});