nextjs-indexing-pack
v0.1.2
Published
Submit your nextjs website routes / URLs to Google and IndexNow-compatible search engines
Downloads
50
Maintainers
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
- Quick start
- Installation
- Preparing IndexNow
- Usage
- Configuration reference
- API
- Troubleshooting
- Requirements
- License
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
Install the package in your Next.js project:
npm install nextjs-indexing-packRun the setup wizard after your next build finishes locally:
npx nextjs-indexing-pack initThe wizard:
- asks for your production URL and stores it in
nextjs-indexing-pack.config.json; - generates a compliant IndexNow key and places
<key>.txtin yourpublic/directory; - optionally scaffolds Google Indexing credentials and updates
.env.localfor you.
- asks for your production URL and stores it in
Commit the generated config and key file, keep real secrets out of git, and expose
INDEXNOW_KEY(and optionallyGOOGLE_APPLICATION_CREDENTIALS) to your CI/CD environment.Trigger submissions whenever
next buildcompletes, for example frompackage.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-packPreparing IndexNow
- Generate an IndexNow key (any random 8–128 character string).
- Create a text file named
<key>.txtin the public root of your site that contains the key value. - 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 initThe 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-packNeed 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 -gThe 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 innextjs-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 toGOOGLE_APPLICATION_CREDENTIALSenv var or the config file).--google-notification-type <type>– switch betweenURL_UPDATED(default) andURL_DELETEDnotifications 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 .nextFor example, run a dry run to inspect the URLs that will be submitted:
npx nextjs-indexing-pack --dry-runTip: 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: trueto 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
- Create a Google Cloud project and enable the Indexing API.
- Generate a service account with the
Indexing APIscope and download the JSON credentials. - Share the verified Search Console property with the service account email address.
- 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 buildwas run and the.nextdirectory exists before running the CLI or scripts. - IndexNow rejects the key – verify the
<key>.txtfile is deployed athttps://your-domain.com/<key>.txtand 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.jsonand 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
fetchAPI)
License
MIT © nextjs-indexing-pack
