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

@ipgeotrace/express

v0.1.0

Published

Express middleware for IPGeoTrace. Resolves the caller's location once per request and exposes it on req.geo.

Readme

@ipgeotrace/express

Express middleware for IPGeoTrace. Resolves the caller's location once per request and hands it to you on req.geo. Built on @ipgeotrace/client — the secret key stays server-side.

Sign up and grab your API key at ipgeotrace.com.

Install

npm add @ipgeotrace/express express

Usage

import express from 'express';
import { ipgeotrace, getGeo } from '@ipgeotrace/express';

const app = express();

app.set('trust proxy', true); // so req.ip reads X-Forwarded-For behind a proxy / load balancer
app.use(ipgeotrace({ apiKey: process.env.IPGEOTRACE_API_KEY! }));

app.get('/checkout', (req, res) => {
  const geo = getGeo(req);
  const currency = geo.status === 'resolved' ? geo.value?.country?.currency ?? 'USD' : 'USD';
  res.json({ currency });
});

req.geo (and getGeo(req)) is a GeoLookup whose status tells you exactly what happened:

  • resolvedvalue carries the data.
  • skipped — the caller's IP was missing, private, loopback, or link-local, so no API call was made.
  • failederror carries the reason (rate_limited, quota_exceeded, …).
  • not_attempted — the middleware opted out for this request (shouldResolve returned false).

getGeo() is always safe to call and returns not_attempted when the middleware never ran.

Skipping requests

Health checks and internal endpoints should not spend lookups. Opt them out with shouldResolve:

app.use(ipgeotrace({
  apiKey: process.env.IPGEOTRACE_API_KEY!,
  shouldResolve: (req) => !req.path.startsWith('/health') && !req.path.startsWith('/internal'),
}));

Private, loopback, and link-local addresses (including IPv4-mapped IPv6) are detected locally and skipped without an API call or quota usage.

Choosing the caller's IP

By default the middleware uses req.ip, which respects Express's trust proxy setting. For full control, supply your own selector:

app.use(ipgeotrace({
  apiKey: process.env.IPGEOTRACE_API_KEY!,
  ipSelector: (req) => req.header('cf-connecting-ip') ?? req.ip,
}));

Configuration

Pass client options through clientOptions, or share a pre-built client across your app:

import { IpGeoTraceClient } from '@ipgeotrace/client';

// inline client options
app.use(ipgeotrace({
  apiKey: process.env.IPGEOTRACE_API_KEY!,
  clientOptions: { cache: true, cacheTtlMs: 6 * 60 * 60_000, timeoutMs: 3_000 },
}));

// or bring your own client (also usable directly in services)
const client = new IpGeoTraceClient({ apiKey: process.env.IPGEOTRACE_API_KEY!, cache: true });
app.use(ipgeotrace({ client }));

See the @ipgeotrace/client README for caching, retries, timeouts, and batch lookups.