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 🙏

© 2026 – Pkg Stats / Ryan Hefner

ip-details-harshil

v1.0.0

Published

Fast and resilient IP geolocation & address lookup for Node.js with built-in automatic backup API failover.

Downloads

41

Readme

ip-details-harshil 🚀

Fast, lightweight, and resilient IP geolocation & address lookup for Node.js with built-in automatic backup API failover.

npm version license node version


✨ Features

  • 📍 Detailed IP Geolocation: Get city, state/region, country, ISO country code, postal code, latitude, longitude, timezone, and ISP/organization.
  • 🛡️ Built-in Failover / Backup API: If the primary geolocation API fails (timeout, rate limit, HTTP error), ip-details-harshil automatically switches to backup APIs seamlessly.
  • ⚡ Zero External Dependencies: Powered by native fetch and AbortController (Node 18+).
  • 📦 Dual Module Support: Works out of the box with ES Modules (import) and CommonJS (require).
  • 🔷 TypeScript Native: Includes full TypeScript declarations (.d.ts).
  • ⚙️ Fully Configurable: Custom timeouts, custom provider order, debug mode, and custom provider adapters.

👤 Author

Harshil Patel


📦 Installation

npm install ip-details-harshil

🚀 Quick Start

1. Fetch Caller's Public IP & Location Details

import { getIpDetails } from 'ip-details-harshil';

// Get geolocation for your own public IP address
const details = await getIpDetails();

console.log(details);
/*
{
  ip: '2405:f600:34:91be:...',
  city: 'Ahmedabad',
  state: 'Gujarat',
  country: 'India',
  countryCode: 'IN',
  postalCode: '380001',
  latitude: 23.0215,
  longitude: 72.5800,
  timezone: 'Asia/Kolkata',
  isp: 'Ishan s Network',
  sourceApi: 'ipwhois'
}
*/

2. Fetch Details for a Specific IP Address

import { getIpDetails } from 'ip-details-harshil';

const details = await getIpDetails('8.8.8.8');

console.log(`IP: ${details.ip}`);
console.log(`Location: ${details.city}, ${details.state}, ${details.country}`);
console.log(`Postal Code: ${details.postalCode}`);
console.log(`Provided by: ${details.sourceApi}`);

3. Quick Helper: Get Only Public IP

import { getPublicIp } from 'ip-details-harshil';

const myIp = await getPublicIp();
console.log(`Your IP is: ${myIp}`);

4. CommonJS Usage (require)

const { getIpDetails, getPublicIp } = require('ip-details-harshil');

getIpDetails('1.1.1.1').then(details => {
  console.log(details.country, details.sourceApi);
});

🔄 How the Backup API Fallback Works

ip-details-harshil maintains a default chain of high-availability geolocation providers:

  1. ipwhois (https://ipwho.is/) — Primary API
  2. freeipapi (https://freeipapi.com/api/json/) — Backup API 1
  3. ipapi (https://ipapi.co/json/) — Backup API 2

If the primary API fails (e.g. timeout, network down, 5xx server error), ip-details-harshil silently catches the error and immediately queries the next backup API in the list.

Enabling Failover Logs (Debug Mode)

const details = await getIpDetails('8.8.8.8', {
  debug: true
});

Console output if Primary API fails:

[ip-details-harshil] Provider "ipwhois" failed: 503 Service Unavailable. Trying backup provider...

⚙️ Advanced Configuration Options

You can pass an optional options object to getIpDetails(ip, options):

| Option | Type | Default | Description | | :--- | :--- | :--- | :--- | | timeout | number | 5000 | Request timeout in milliseconds per provider | | providers | (string \| ProviderFunction)[] | ['ipwhois', 'freeipapi', 'ipapi'] | Array of provider names or custom provider functions | | debug | boolean | false | Log warnings when a provider fails and switches to backup |

Customizing Provider Fallback Order & Timeout

const details = await getIpDetails('8.8.8.8', {
  timeout: 3000, // 3 seconds timeout per API
  providers: ['freeipapi', 'ipwhois'], // Custom priority order
  debug: true
});

Adding Custom API Providers

You can define your own custom geolocation provider function:

const customProvider = {
  name: 'my-custom-geo-api',
  async fetchDetails(ip, timeoutMs) {
    // Custom fetch logic
    return {
      ip: ip,
      city: 'Custom City',
      state: 'Custom State',
      country: 'Custom Country',
      countryCode: 'CC',
      postalCode: '123456',
      latitude: 0,
      longitude: 0,
      timezone: 'UTC',
      isp: 'Custom ISP',
      sourceApi: 'my-custom-geo-api'
    };
  }
};

const details = await getIpDetails('8.8.8.8', {
  providers: [customProvider, 'ipwhois']
});

📋 Response Schema Reference (IpDetails)

| Field | Type | Description | | :--- | :--- | :--- | | ip | string | The target IPv4 or IPv6 address | | city | string \| null | City name | | state | string \| null | State or region name | | country | string \| null | Country name | | countryCode | string \| null | ISO 2-letter country code (e.g. US, IN) | | postalCode | string \| null | Postal or ZIP code | | latitude | number \| null | Latitude coordinate | | longitude | number \| null | Longitude coordinate | | timezone | string \| null | Timezone identifier (e.g. America/New_York) | | isp | string \| null | ISP or Organization name | | sourceApi | string | Name of the API that successfully provided the data |


📜 License

MIT © Harshil Patel