IPDox is a simple and efficient IP geolocation library for Node.js. It fetches data from multiple geolocation APIs and provides a unified response. It also includes a caching mechanism to prevent unnecessary requests.
Current keyless providers used:
- ip-api.com
- ipwho.is
- freeipapi.com
- ipapi.co
Note: ip-api.com free tier uses HTTP only. Provide ipApiKey to enable HTTPS (pro).
Fallback providers (best-effort, used after primary providers fail):
- geoip.vuiz.net
- apip.cc
- ip-sonar.com
Fallback providers can return partial data; city may be an empty string when unknown.
npm install node-ipdox --saveimport { IPDox } from "node-ipdox";
const ipdox = new IPDox({
cacheMaxItems: 5000,
cacheMaxAge: 43200000,
maxRetries: 10,
requestTimeoutMs: 5000,
ipApiKey: "YOUR_IP_API_KEY"
});
ipdox
.doxIP({ ip: "8.8.8.8" })
.then(response => console.log(response))
.catch(error => console.error(error));Creates a new instance of IPDox.
cacheMaxItems- The maximum number of items to store in the cache (default: 1000)cacheMaxAge- The cache timeout in milliseconds (default: 43200000 (12 hours))maxRetries- Maximum number of retries if an API request fails (default: 10)requestTimeoutMs- Request timeout in milliseconds (default: 5000)ipApiKey- Optional ip-api.com pro API key to enable HTTPS
Fetches geolocation data for the specified IP address.
ip- IP address
Returns a Promise that resolves to an IPDOXResponse object.
If no response is found or the IP is invalid, undefined is returned.
The IPDOXResponse object includes the following properties:
export interface IPDOXResponse {
ip: string; // IP address
country: string; // Country ISO code
city: string; // City name
continent: string; // Continent ISO code
latitude: number; // Latitude
longitude: number; // Longitude
zip?: string; // Zip code (might be undefined)
isp?: string; // ISP name (might be undefined)
proxy?: boolean; // Boolean indicating if the IP address is a proxy (might be undefined)
isHosting?: boolean; // Boolean indicating if the IP address is a hosting provider (might be undefined)
proxyInfo?: {
// Proxy information (might be undefined)
isVPN: boolean; // Boolean indicating if the IP address is a VPN (might be undefined)
isTOR: boolean; // Boolean indicating if the IP address is a TOR node (might be undefined)
isProxy: boolean; // Boolean indicating if the IP address is a proxy (might be undefined)
};
timeZone?: string; // Time zone
source: string; // Source API
}Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
This project is licensed under the ISC License.