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 🙏

© 2025 – Pkg Stats / Ryan Hefner

nextjs-indexing-pack

v0.1.2

Published

Submit your nextjs website routes / URLs to Google and IndexNow-compatible search engines

Downloads

50

Readme

Nextjs Indexing Pack

Submit every valid route in your Next.js build to IndexNow and the search engines that support it.

Why nextjs-indexing-pack

Don't rely on Google and other search engines randomly stumbling upon your latest product launch, seasonal landing page, or blog update. nextjs-indexing-pack gives you proactive control over how quickly fresh URLs reach the crawlers, so you can turn marketing campaigns, news announcements, or inventory updates into real traffic while they are still timely.

Inspired by the proven results of the Rank Math Instant Indexing approach, this package tailors that playbook for modern Next.js stacks. You get a single, reliable workflow that respects your CI/CD process, pairs perfectly with the framework's build output, and keeps your website visible across IndexNow partners and the Google Indexing API without waiting for chance discovery.

Table of contents

What it does

  • 📄 Reads your Next.js website build output and compiles a clean list of public URLs (excluding 404/error utilities).
  • 🚀 Sends the URLs to IndexNow-compatible endpoints (IndexNow, Bing, Yandex, Naver) with one call.
  • 🌐 Publishes (if configured) the same URLs to the Google Indexing API using a service account.
  • 🧪 Supports dry-run mode so you can verify which URLs will be submitted before notifying search engines.

Quick start

  1. Install the package in your Next.js project:

    npm install nextjs-indexing-pack
  2. Run the setup wizard after your next build finishes locally:

    npx nextjs-indexing-pack init

    The wizard:

    • asks for your production URL and stores it in nextjs-indexing-pack.config.json;
    • generates a compliant IndexNow key and places <key>.txt in your public/ directory;
    • optionally scaffolds Google Indexing credentials and updates .env.local for you.
  3. Commit the generated config and key file, keep real secrets out of git, and expose INDEXNOW_KEY (and optionally GOOGLE_APPLICATION_CREDENTIALS) to your CI/CD environment.

  4. Trigger submissions whenever next build completes, for example from package.json:

    {
      "scripts": {
        "build": "next build",
        "postbuild": "INDEXNOW_KEY=$INDEXNOW_KEY npx nextjs-indexing-pack"
      }
    }

Installation

The package ships as plain TypeScript utilities so it can be wired into any build or deployment workflow.

npm install nextjs-indexing-pack

Preparing IndexNow

  1. Generate an IndexNow key (any random 8–128 character string).
  2. Create a text file named <key>.txt in the public root of your site that contains the key value.
  3. Deploy the file so it is accessible at https://your-domain.com/<key>.txt.

Refer to the official IndexNow documentation for detailed requirements. The init wizard (see CLI) can create and place the key file for you.

Usage

CLI (recommended)

Kick off your integration with the interactive init wizard:

npx nextjs-indexing-pack init

The wizard asks for your production URL, generates a compliant IndexNow key, creates the required public/<key>.txt file, writes nextjs-indexing-pack.config.json, and can optionally scaffold a dummy Google service account JSON credential file while storing the references in .env.local.

Once you are set up, trigger submissions directly from your build or deployment pipeline:

npx nextjs-indexing-pack

Need to push a short list of specific URLs without waiting for a new build? Use the explicit submit command and pass a comma-separated list:

npx nextjs-indexing-pack submit -u https://example.com/new-page,https://example.com/updated-offer -g

The example above targets only the Google Indexing API (-g). Omit both -g and -i to notify IndexNow partners and Google together, or pass -i when you only want IndexNow-compatible endpoints.

Configuration

The CLI stores persistent settings in nextjs-indexing-pack.config.json at the project root. The file follows this shape:

{
  "baseUrl": "https://your-production-domain.com",
  "googleServiceAccountPath": "./credentials/google-service-account.json"
}
  • baseUrl – the origin that the CLI prefixes to every discovered route when it assembles the submission payload. Update this value when promoting builds between staging and production or when sending URLs for alternate domains.
  • googleServiceAccountPath (optional) – path to a Google service account JSON file if you also submit to the Google Indexing API. The wizard only adds this when you opt into Google support.

If the file is missing or you need to regenerate it, run npx nextjs-indexing-pack init to recreate it from the interactive wizard, or delete and rerun the command to start fresh. Manual edits are safe when you need different values for specific deployment environments (for example, custom staging hosts in CI). During a submission run, the CLI first loads nextjs-indexing-pack.config.json and falls back to CLI flags or environment variables when fields are absent, so changes are picked up automatically on the next execution.

Optional flags:

  • -u, --urls <list> – provide a comma-separated set of fully qualified URLs to submit manually instead of discovering them from the Next.js build.
  • -g, --google – limit the run to the Google Indexing API (default is both IndexNow and Google).
  • -i, --indexnow – limit the run to IndexNow-compatible endpoints (default is both IndexNow and Google).
  • --base-url <url> – override the base URL stored in nextjs-indexing-pack.config.json.
  • --next-build-dir <dir> – override the location of your Next.js build output (defaults to .next).
  • --dry-run – collect URLs without notifying any endpoints.
  • --google-service-account <path> – override the Google service account credentials path (defaults to GOOGLE_APPLICATION_CREDENTIALS env var or the config file).
  • --google-notification-type <type> – switch between URL_UPDATED (default) and URL_DELETED notifications for the Google Indexing API.

If you do not pass --key, the CLI will automatically fall back to the INDEXNOW_KEY environment variable.

If GOOGLE_APPLICATION_CREDENTIALS (or nextjs-indexing-pack.config.json) points to a service account JSON file, the CLI will automatically notify the Google Indexing API as well. When the credentials are missing required fields or contain placeholder values, the CLI skips the Google submission and continues with IndexNow so your default workflow is not interrupted.

Need to drive everything non-interactively in CI? Pre-populate config values and rely on environment variables:

INDEXNOW_KEY=your-key GOOGLE_APPLICATION_CREDENTIALS=./google-service-account.json npx nextjs-indexing-pack \
  --base-url https://www.example.com \
  --next-build-dir .next

For example, run a dry run to inspect the URLs that will be submitted:

npx nextjs-indexing-pack --dry-run

Tip: wire it into your pipeline after next build finishes, for example "postbuild": "INDEXNOW_KEY=$INDEXNOW_KEY npx nextjs-indexing-pack".

Using the TypeScript API

Prefer to keep using the library? Create a small script (for example in scripts/submit-indexnow.ts) and run it after next build finishes.

import { submitToGoogleIndexing, submitToIndexNow } from 'nextjs-indexing-pack';

async function main() {
  const result = await submitToIndexNow({
    baseUrl: 'https://your-domain.com',
    key: process.env.INDEXNOW_KEY!,
    nextBuildDir: '.next',
  });

  console.log(`Submitted ${result.urls.length} URLs to IndexNow.`);
  console.log(result.responses);

  if (process.env.GOOGLE_APPLICATION_CREDENTIALS) {
    const googleResult = await submitToGoogleIndexing({
      baseUrl: 'https://your-domain.com',
      serviceAccountPath: process.env.GOOGLE_APPLICATION_CREDENTIALS,
      nextBuildDir: '.next',
    });
    console.log(`Submitted ${googleResult.urls.length} URLs to the Google Indexing API.`);
    console.log(googleResult.responses);
  }
}

main().catch((error) => {
  console.error('IndexNow submission failed:', error);
  process.exit(1);
});

Add a script entry so you can call it easily:

{
  "scripts": {
    "build": "next build",
    "postbuild": "tsx scripts/submit-indexnow.ts"
  }
}

💡 Prefer to test first? Pass dryRun: true to only list the URLs without notifying any endpoint.

Customising submissions

import { submitToIndexNow } from 'nextjs-indexing-pack';

await submitToIndexNow({
  baseUrl: 'https://your-domain.com',
  key: process.env.INDEXNOW_KEY!,
  nextBuildDir: '.next',
  endpoints: ['https://www.bing.com/indexnow'], // override the default list
  urlFilter: (url) => !url.includes('/drafts'),   // exclude URLs you do not want to submit
});

Configuration reference

nextjs-indexing-pack.config.json

The CLI automatically creates this file when you run npx nextjs-indexing-pack init. It lives in your project root and stores non-secret defaults that work in all environments.

| Field | Type | Description | | --- | --- | --- | | baseUrl | string | Production origin used to build absolute URLs (e.g. https://www.example.com). | | googleServiceAccountPath | string | Relative or absolute path to the Google service account JSON file. |

Commit the file so your CI environment inherits the same defaults. Secrets such as the actual service account JSON should not be committed—store the file in a secure secret manager or deployment bucket and reference it from the config.

Environment variables

| Variable | Purpose | | --- | --- | | INDEXNOW_KEY | Required IndexNow key. Used automatically by the CLI and TypeScript helpers. | | GOOGLE_APPLICATION_CREDENTIALS | Path to the Google service account credentials used for the Indexing API (optional). | | NEXTJS_INDEXING_PACK_BASE_URL | Optional override if you cannot edit the config file in the current environment. |

Environment variables always take precedence over config file values when you pass the corresponding CLI flags (for example --base-url). This makes it easy to test changes temporarily without editing the committed config.

Google Indexing API prerequisites

  1. Create a Google Cloud project and enable the Indexing API.
  2. Generate a service account with the Indexing API scope and download the JSON credentials.
  3. Share the verified Search Console property with the service account email address.
  4. Point GOOGLE_APPLICATION_CREDENTIALS (or the config file) at the JSON credentials.

The init wizard can scaffold a dummy JSON file so you can wire everything up before obtaining real credentials.

API

submitToIndexNow(options)

Collects URLs from the Next.js build directory and notifies IndexNow-compatible endpoints.

| Option | Type | Description | | --- | --- | --- | | baseUrl | string | Fully qualified origin to prepend to each discovered route. | | nextBuildDir | string | Location of the .next build directory (defaults to .next). | | key | string | IndexNow key value. | | keyLocation | string | Absolute URL pointing to the key file (defaults to ${baseUrl}/${key}.txt). | | endpoints | string[] | Endpoints to notify (defaults to IndexNow, Bing, Yandex, Naver). | | urlFilter | (url: string) => boolean | Optional filter callback for excluding URLs from submission. | | dryRun | boolean | When true, URLs are collected but not submitted. |

Returns a promise resolving to:

{
  urls: string[]; // URLs that were collected from the Next.js build output
  responses: Record<string, { status: number; ok: boolean; body?: string }>;
}

collectIndexableRoutes(nextBuildDir?)

Utility helper that returns the raw list of routes (without base URL) discovered in the specified .next directory. This can be used if you want to roll your own submission logic.

submitToGoogleIndexing(options)

Publishes URLs to the Google Indexing API using a service account.

| Option | Type | Description | | --- | --- | --- | | baseUrl | string | Fully qualified origin to prepend to each discovered route. | | serviceAccountPath | string | Path to the Google service account JSON credentials. | | nextBuildDir | string | Location of the .next build directory (defaults to .next). | | urlFilter | (url: string) => boolean | Optional filter callback for excluding URLs from submission. | | dryRun | boolean | When true, URLs are collected but not submitted. | | notificationType | 'URL_UPDATED' | 'URL_DELETED' | Notification type sent to the Indexing API (defaults to URL_UPDATED). |

Returns a promise resolving to:

{
  urls: string[]; // URLs that were collected from the Next.js build output
  responses: Array<{ url: string; status: number; ok: boolean; body?: string }>;
}

Troubleshooting

  • No URLs are submitted – ensure next build was run and the .next directory exists before running the CLI or scripts.
  • IndexNow rejects the key – verify the <key>.txt file is deployed at https://your-domain.com/<key>.txt and contains the exact key value.
  • Google Indexing API requests fail – confirm the service account has access to your Search Console property and that the JSON credentials path is valid.
  • CI cannot find the config file – commit nextjs-indexing-pack.config.json and double-check the working directory in your pipeline before running the CLI.

Requirements

  • Next.js ≥ 12
  • Node.js ≥ 18 (IndexNow submission relies on the built-in fetch API)

License

MIT © nextjs-indexing-pack