This is the official NodeJS client library for the IPinfo.io IP data API, allowing you to lookup your own IP address, or get any of the following details for an IP:
- IP geolocation data (city, region, country, postal code, latitude and longitude)
- ASN details (ISP or network operator, associated domain name, and type, such as business, hosting or company)
- Company data (the name and domain of the business that uses the IP address)
- Carrier information (the name of the mobile carrier and MNC and MCC for that carrier if the IP is used exclusively for mobile traffic)
Check all the data we have for your IP address here.
Works with ES5, ES6+ and TypeScript.
You'll need an IPinfo API access token, which you can get by signing up for a free account at https://ipinfo.io/signup.
The free plan is limited to 50,000 requests per month, and doesn't include some of the data fields such as IP type and company data. To enable all the data fields and additional request volumes see https://ipinfo.io/pricing.
npm install node-ipinfo
import IPinfoWrapper, { IPinfo, AsnResponse } from "node-ipinfo";
const ipinfoWrapper = new IPinfoWrapper("MY_TOKEN");
ipinfoWrapper.lookupIp("1.1.1.1").then((response: IPinfo) => {
console.log(response);
});
ipinfoWrapper.lookupASN("AS7922").then((response: AsnResponse) => {
console.log(response);
});
let { IPinfoWrapper } = require("node-ipinfo");
let ipinfo = new IPinfo("MY_TOKEN");
ipinfo.lookupIp("1.1.1.1").then((response) => {
console.log(response);
});
ipinfo.lookupASN("AS7922").then((response) => {
console.log(response);
});
This library uses an LRU cache (deletes the least-recently-used items).
If you prefer a different caching methodology, you may use the IPCache
interface through TypeScript and implement your own caching system around your own infrastructure.
The default cache length is 1 day and the defauly max number of items allowed in the cache is 5000. This can be changed by passing an Option
to the LruCache
constructor.
import IPinfoWrapper, { LruCache, Options } from "node-ipinfo";
const cacheOptions: Options<string, any> = {
max: 5000,
maxAge: 24 * 1000 * 60 * 60,
};
let cache = new LruCache(cacheOptions);
let ipinfoWrapper = new IPinfoWrapper("MY_TOKEN", cache);
let { IPinfoWrapper, LruCache } = require("node-ipinfo");
let cacheOptions = {
max: 5000,
maxAge: 24 * 1000 * 60 * 60,
};
let cache = new LruCache(cacheOptions);
let ipinfo = new IPinfo("MY_TOKEN", cache);
The client constructor accepts a timeout
parameter in milliseconds that
controls the timeout of requests. It defaults to 5000
i.e. 5 seconds.
A timeout of 0
disables the timeout feature.
import IPinfoWrapper from "node-ipinfo";
// 10 second timeout.
let ipinfoWrapper = new IPinfoWrapper("MY_TOKEN", null, 10000);
let { IPinfoWrapper } = require("node-ipinfo");
// 10 second timeout.
let ipinfo = new IPinfoWrapper("MY_TOKEN", null, 10000);
// example coming soon
// example coming soon
// example coming soon
Get great code completion for this package using the integrated typescript typings. It includes the complete typings of the IPinfo API too, so you'll know both how to the navigate the API as well as the response you are getting.
In order to run the tests, run:
$ npm run test
If you want to check out the coverage, run:
$ npm run test:coverage
There are official IPinfo client libraries available for many languages including PHP, Python, Go, Java, Ruby, and many popular frameworks such as Django, Rails and Laravel. There are also many third party libraries and integrations available for our API.
https://ipinfo.io/developers/libraries
Founded in 2013, IPinfo prides itself on being the most reliable, accurate, and in-depth source of IP address data available anywhere. We process terabytes of data to produce our custom IP geolocation, company, carrier, privacy detection (VPN, proxie, Tor), hosted domains, and IP type data sets. Our API handles over 40 billion requests a month for 100,000 businesses and developers.