Route visitors to a regional site, language, or pricing page based on the country of their IP address.
Read the visitor's IP from the incoming request and ask the API for its country. Keep your key on the server.
// Node/Express
app.get("/", async (req, res) => {
const ip = req.headers["x-forwarded-for"]?.split(",")[0] || req.socket.remoteAddress;
const r = await fetch(`https://ipquery.info/api?apiKey=YOUR_API_KEY&ip=??ip??`);
const country = (await r.json())[0]?.country_iso_code;
const map = { GB: "/uk", DE: "/de", US: "/us" };
res.redirect(map[country] || "/us");
});
country_iso_codeThe response is an array with one object per IP. Use country_iso_code (ISO 3166-1 alpha-2, e.g. GB) for routing; continent and is_eu_member are handy for coarser rules.
Cache the result per IP (or per /24) for a few hours so repeat visits don't spend additional requests. Bulk lookups cost one request per address, so single look-ups are best for per-visitor routing.
See the full field reference for everything you can route on.