JavaScript SDK · Feature

IP Geolocation in Node.js

Turn any IP address into geolocation, network, and threat intelligence with one call. The lookup method on the official ip-api-io client returns the country, city, coordinates, timezone, ISP, and ASN of an IP — plus the suspicious_factors flags used for fraud screening — in a single typed response.

Trusted by thousands of businesses
Fast JSON API responses
Real-time validation
Simple integration, SDKs & examples
What it does

Geolocation without browser GPS

IP-based geolocation works entirely server-side — no permission prompt, no client SDK, and it works for every visitor and every log line you already have. ip-api.io resolves an IP to a physical location and, uniquely, returns security signals (VPN, proxy, Tor, datacenter, threat) in the same response, so you can localize content and screen for fraud in one round trip.

Prerequisites

  • Node.js 18 or higher
  • The ip-api-io package installed (npm install ip-api-io)
  • A free ip-api.io API key
1

Geolocate one IP with lookup

Pass any IPv4 or IPv6 address, or omit the argument to geolocate the caller's own IP.

import { IpApiClient } from "ip-api-io";

const client = new IpApiClient({ apiKey: process.env.IP_API_IO_KEY });

const info = await client.lookup("8.8.8.8");

console.log(info.ip);                       // "8.8.8.8"
console.log(info.isp);                       // "Google LLC"
console.log(info.location.country);          // "United States"
console.log(info.location.city);             // "Mountain View"
console.log(info.location.latitude,
            info.location.longitude);
console.log(info.location.timezone);         // "America/Los_Angeles"
console.log(info.suspicious_factors.is_datacenter); // true

Resolve the IP of the machine making the request by calling lookup() with no argument:

const me = await client.lookup();
console.log(me.ip, me.location.country);
Behind a proxy? Pass the real client IP from the X-Forwarded-For header to lookup(ip) rather than relying on the socket address. See the SDK overview for an Express example.
2

Geolocate up to 100 IPs with lookupBatch

Enrich logs, sign-up events, or historical data without a round trip per IP. The SDK validates the limit client-side and throws a RangeError if the array is empty or longer than 100.

const batch = await client.lookupBatch(["8.8.8.8", "1.1.1.1", "9.9.9.9"]);

console.log(batch.total_processed);     // 3
console.log(batch.successful_lookups);  // 3
console.log(batch.failed_lookups);      // 0

for (const [ip, info] of Object.entries(batch.results)) {
  console.log(ip, info.location.country, info.suspicious_factors.is_vpn);
}
Reference

Response reference

lookup() resolves to a typed IpInfo. Location fields are nullable for private or unrecognized addresses.

FieldTypeDescription
ipstringThe looked-up address
ispstring | nullInternet service provider
asnstring | nullAutonomous system the IP belongs to
locationobjectcountry, country_code, city, latitude, longitude, zip, timezone, local_time, local_time_unix, is_daylight_savings
suspicious_factorsobjectis_proxy, is_vpn, is_tor_node, is_datacenter, is_spam, is_crawler, is_threat
FAQ

Frequently asked questions

How do I get the location of an IP address in Node.js?

Install ip-api-io, create a client with your API key, and call await client.lookup(ip). The returned IpInfo has a location object with country, city, latitude, longitude and timezone, plus a suspicious_factors object with VPN/proxy/Tor flags.

Can I geolocate the caller's own IP without passing an address?

Yes. Call client.lookup() with no argument and the API resolves the IP from the request. Behind a proxy, pass the real client IP from the X-Forwarded-For header to client.lookup(ip) instead.

How do I look up many IP addresses at once?

Use client.lookupBatch(ips) with up to 100 addresses in one request. It returns a results map of IP to IpInfo plus total_processed, successful_lookups and failed_lookups. The SDK throws a RangeError if the array is empty or longer than 100.

Is IP geolocation accurate?

Country-level accuracy is about 99.8% and city-level 85–95% depending on region. Coordinates have a median accuracy radius of roughly 50 km (WGS84). It is ideal for routing, localization, timezone detection and fraud signals — not street-level precision.

Start building with the ip-api.io JavaScript SDK

Install ip-api-io, drop in your free API key, and ship in minutes — one typed client for geolocation, fraud detection, and email validation.

Need support?

Explore how IP-API.io can enhance your security, provide robust bot protection, and improve IP geolocation accuracy for your applications.

Contact Support

Found a bug in the SDK?

The ip-api-io package is open source. Open an issue or pull request on GitHub and we'll take a look.

Open on GitHub