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/next

v0.1.0

Published

Next.js helpers for IPGeoTrace. Resolve the caller's location in Route Handlers, Server Components, and edge middleware.

Readme

@ipgeotrace/next

Next.js helpers for IPGeoTrace. Resolve the caller's location in Route Handlers, Server Components, and edge middleware. Built on @ipgeotrace/client — the secret key stays server-side.

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

Works on the Node and edge runtimes (the core client is fetch-based and dependency-free). App Router (Next 13+).

Client Components ('use client') can't use the secret key. To read the visitor's location in the browser, use @ipgeotrace/browser (or the upcoming @ipgeotrace/react hook) with a publishable key.

Install

npm add @ipgeotrace/next

Create the resolver once and reuse it:

// lib/geo.ts
import { createGeo } from '@ipgeotrace/next';

export const geo = createGeo({
  apiKey: process.env.IPGEOTRACE_API_KEY!,
  clientOptions: { cache: true },
});

Route Handler

// app/api/geo/route.ts
import { NextRequest, NextResponse } from 'next/server';
import { geo } from '@/lib/geo';

export async function GET(request: NextRequest) {
  const lookup = await geo.resolve(request);
  return NextResponse.json(lookup);
}

Server Component

headers() from next/headers is a valid source:

// app/page.tsx
import { headers } from 'next/headers';
import { geo } from '@/lib/geo';

export default async function Page() {
  const lookup = await geo.resolve(await headers());
  const currency = lookup.status === 'resolved' ? lookup.value?.country?.currency ?? 'USD' : 'USD';
  return <PriceList currency={currency} />;
}

resolve() returns a GeoLookup whose status is resolved | skipped | failed | not_attempted. Private, loopback, and link-local callers are skipped locally with no API call.

Edge middleware — resolve once, read everywhere

Resolve at the edge and pass the result downstream as a request header so Server Components and Route Handlers reuse it instead of each calling the API:

// middleware.ts
import { NextResponse, type NextRequest } from 'next/server';
import { geo } from '@/lib/geo';
import { GEO_HEADER, encodeGeoHeader } from '@ipgeotrace/next';

export async function middleware(request: NextRequest) {
  const lookup = await geo.resolve(request);

  const headers = new Headers(request.headers);
  headers.set(GEO_HEADER, encodeGeoHeader(lookup));
  return NextResponse.next({ request: { headers } });
}

export const config = { matcher: ['/((?!_next|favicon.ico).*)'] };

Then read it anywhere without another lookup:

import { headers } from 'next/headers';
import { readGeoHeader } from '@ipgeotrace/next';

const lookup = readGeoHeader(await headers());

Choosing the caller's IP

By default getCallerIp reads x-forwarded-for (first entry), then x-real-ip, then a platform ip field if present. Override per resolver:

export const geo = createGeo({
  apiKey: process.env.IPGEOTRACE_API_KEY!,
  ipSelector: (source) => {
    const headers = source instanceof Headers ? source : source.headers;
    return headers.get('cf-connecting-ip') ?? undefined;
  },
});

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