How to get Google search results in Node.js

Checked on 2026-11-24.

The official answer is Google's Custom Search JSON API, and its documentation now says it is closed to new customers and that existing customers have until January 1, 2027 to move. Here is what is left in Node.js: the official API if you already have it, what Google points to instead, why the npm packages that fetched google.com stopped, and an HTTP API that returns the organic results as JSON.

1. The Custom Search JSON API, if you already have it

Google's official API answers from a Programmable Search Engine that you create first, and its REST page names three required parameters: the API key (key), the search engine ID (cx) and the search (q). With fetch:

JavaScript
const url = new URL('https://www.googleapis.com/customsearch/v1');
url.searchParams.set('key', process.env.GOOGLE_API_KEY);
url.searchParams.set('cx', process.env.GOOGLE_SEARCH_ENGINE_ID); // your Programmable Search Engine
url.searchParams.set('q', 'best crm software');

const res = await fetch(url);
if (!res.ok) throw new Error(`Custom Search answered ${res.status}`);
const { items = [] } = await res.json();
for (const item of items) console.log(item.title, item.link, item.snippet);

The googleapis package wraps the same request as customsearch('v1').cse.list(). Either way, num is at most 10 results per request, and the reference adds that "The JSON API will never return more than 100 results, even if more than 100 documents match the query." The prices on the overview: "100 search queries per day for free", then "$5 per 1000 queries, up to 10k queries per day".

Where it stops: for anyone new, before it starts. The overview page says: "The Custom Search JSON API is closed to new customers." And: "Existing Custom Search JSON API customers have until January 1, 2027 to transition to an alternative solution." If you depend on it, the Custom Search API alternative page maps its fields to another API, one by one, and lists what does not carry over.

2. What Google points to instead

  • Vertex AI Search, which the same overview calls "a favorable alternative for searching up to 50 domains". That is search over sites you choose, not over the whole web.
  • Full web search: for a use case that needs it, the overview asks you to contact Google.
  • Grounding with Google Search in the Gemini API, which "connects the Gemini model to real-time web content". It is for AI applications: you get an answer written by the model, with the sources it cites.

Where it stops: none of the three hands you Google's ranked results for any search today.

3. npm packages that fetch google.com/search

Several npm packages were written to fetch Google's results page and parse it. Two of them show where that road ends:

  • google-sr is deprecated on npm and its repository is archived. Its maintainer's notice explains that the package's way of fetching the results page no longer works, and the edit of 20 December 2025 says: "I’ve decided to permanently deprecate and archive this package. I don’t see a path forward where it would continue to work."
  • googlethis: the description of its repository says "This project is no longer being maintained." Its latest version on npm, 1.8.0, came out on 18 September 2023.

Writing the same thing yourself meets three obstacles, all published by Google. google.com/robots.txt has Disallow: /search for all crawlers. Google's Terms of Service (effective July 30, 2026) list among the things you must not do "using automated means to access content from any of our services in violation of the machine-readable instructions" on its web pages, robots.txt files among them. And its help page says a network that "seems to be sending automated traffic to Google Search" may get the message "Our systems have detected unusual traffic from your computer network", most likely with a reCAPTCHA; "Search scrapers" are on its list of what counts.

Where it breaks: at that block, and at any change to the page's HTML, which is not a documented format. This guide does not cover getting around the block.

4. An HTTP API that returns the organic results

With Pipefetch a search is one GET request that returns the first page of results as JSON. A plain fetch call, from Node.js 18 or newer or a serverless function:

JavaScript
const url = new URL('https://pipefetch.com/v1/google/search');
url.searchParams.set('q', 'best crm software');
url.searchParams.set('country', 'US');
url.searchParams.set('lang', 'en');

const res = await fetch(url, {
  headers: { 'x-api-key': process.env.PIPEFETCH_API_KEY },
  signal: AbortSignal.timeout(90_000),
});
if (res.status === 404) {
  console.log('Google has no results for this search'); // not charged
} else if (res.status === 502) {
  console.log('Google refused this search, send it again'); // not charged
} else if (!res.ok) {
  throw new Error(`Pipefetch answered ${res.status}`);
} else {
  const { data } = await res.json();
  for (const result of data.results) console.log(result.position, result.title, result.url);
  for (const related of data.relatedSearches) console.log('related:', related.query);
}

The npm client, pipefetch, reaches it through get(), which takes the path of any endpoint. It sends a search Google refused again by itself, twice, with a growing pause:

JavaScript
// npm install pipefetch
import Pipefetch, { NotFoundError } from 'pipefetch';

const pf = new Pipefetch(); // reads PIPEFETCH_API_KEY

try {
  const { results } = await pf.get('/v1/google/search', { q: 'site:nodejs.org fetch', country: 'GB' });
  for (const r of results) console.log(r.position, r.domain, r.description);
} catch (error) {
  if (error instanceof NotFoundError) console.log('No results'); // not charged
  else throw error;
}

Each result has its position, title, url, displayedUrl, domain, description (the snippet) and, when Google shows one, a date. Google's operators, such as site: and intitle:, work in q. country and lang choose whose Google you get; without a country it is the United States. The reference lists every field.

Where it stops:

  • One request is the first page: about 10 organic results. There are no further pages.
  • It reads the light results page Google serves to clients without JavaScript, not the full page a desktop browser gets. Ads, AI Overview, People also ask, the featured snippet, the places block, top stories, the knowledge panel, videos and images are not included.
  • Results are for a country, not for a city, and for a visitor who is not signed in.
  • Google sometimes refuses a search. The request then answers 502 upstream_error, costs nothing and can be sent again.
  • It is not an official Google API, and Pipefetch is not affiliated with Google. The reading happens on Pipefetch's servers instead of yours, but it is still automated reading of a Google results page, which is what the policies quoted above are about. If you need a route Google itself supports, it is one of the first two.

A request costs 1 credit. A search without results (404) and a refused one (502) cost nothing. A new account has 100 free credits and needs no card, and most requests take 2 to 9 seconds.

Which one should you use?

SituationUse
You already call the Custom Search JSON APIKeep it until January 1, 2027, and plan the move now
Search over your own site or a set of domainsVertex AI Search, as Google's notice suggests
An AI application that needs answers with sourcesGrounding with Google Search in the Gemini API
The organic results of a search as JSON, todayAn HTTP API such as Pipefetch, knowing what it leaves out

Call it from the server, not the page

Every route here needs a key. Make the call in server code, an API route or a serverless function, and send only the results to the page: a key in browser code can be read and spent by anyone. For the same task in Python, see Google search results in Python.

Try it with 100 free credits. No card needed. No scraper to build or maintain. Get an API key or read the docs.

Every source

YouTube

Instagram

Websites

TikTok

Facebook

Threads

LinkedIn

App stores

Steam

X

Pinterest

Airbnb

Real estate

Keywords

Job boards

Eventbrite

Shopify stores

Public tenders

All guides