Menu

Zero-dependency Google Indexing API with Node.js crypto
πŸ“°

Zero-dependency Google Indexing API with Node.js crypto

DEV Community: nodeΒ·XNOW PROΒ·7 days ago
#wfhx0tCQ
#devtonodejs#devto#dev#indexing#const
Reading 0:00
15s threshold

I needed to submit 174 URLs to Google's Indexing API from a production server running Python 3.8 with system pip. The official quickstart uses google-auth , which meant either polluting system packages or spinning up a venv just to run one script.

So I did it with Node's built-in crypto instead. Zero dependencies, no install step.

What the API actually needs

Google's Indexing API takes an OAuth 2.0 access token from a service account. The flow is:

Sign a JWT with the service account's private key (RS256)

Exchange that JWT for an access token

Call the API with Authorization: Bearer <token>

Most tutorials stop at "use the library". Here's what's underneath.

Step 1: sign the JWT

import { createSign } from ' node:crypto ' ; import { readFileSync } from ' node:fs ' ;

const b64url = ( buf ) => Buffer . from ( buf ). toString ( ' base64 ' ) . replace ( / \+ /g , ' - ' ). replace ( / \/ /g , ' _ ' ). replace ( /=+$/ , '' );

const key = JSON .…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.