Query Google from Node.js and get structured JSON, using serp.cheap. Node 18+ has fetch built in — no dependencies needed.
To sanity-check your key first, one curl is enough:
curl -s https://api.serp.cheap/v1/search \
-H "X-API-Key: $SERP_KEY" \
-H "Content-Type: application/json" \
-d '{"q":"best electric cars 2026","gl":"us"}'
Minimal example
Save as search.mjs (top-level await needs ESM) and run with SERP_KEY=... node search.mjs:
const res = await fetch("https://api.serp.cheap/v1/search", {
method: "POST",
headers: { "X-API-Key": process.env.SERP_KEY, "Content-Type": "application/json" },
body: JSON.stringify({ q: "best electric cars 2026", gl: "us", page: 1 }),
});
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const { organic, stats } = await res.json();
organic.forEach(r => console.log(`#${r.position} ${r.title} — ${r.link}`));
console.log("cost (credits):", stats.cost, "cached:", stats.cached);
Output looks like:
#1 The 10 Best Electric Cars of 2026 — https://www.example.com/best-electric-cars-2026
#2 Best EVs for 2026, Tested and Ranked — https://www.example.org/ev-rankings
#3 Electric Car Buying Guide — https://buyersguide.example.net/electric
cost (credits): 6 cached: false
Run the same query again and you’ll see cost (credits): 3 cached: true — cached responses are billed at half the fresh rate.
A small helper with retry
async function search(q, { gl = "us", page = 1, tbs, retries = 4 } = {}) {
const body = JSON.stringify({ q, gl, page, ...(tbs && { tbs }) });
for (let attempt = 0; ; attempt++) {
const res = await fetch("https://api.serp.cheap/v1/search", {
method: "POST",
headers: { "X-API-Key": process.env.SERP_KEY, "Content-Type": "application/json" },
body,
});
if (res.ok) return res.json();
if (![429, 500, 502, 503, 504].includes(res.status) || attempt >= retries) {
throw new Error(`HTTP ${res.status}`);
}
await new Promise(r => setTimeout(r, 1000 * 2 ** attempt)); // backoff
}
}
const data = await search("serp api nodejs", { gl: "us" });
Paginate
Reuse the search() helper from above — no inline fetch duplication. page is 1-indexed:
async function pages(q, n = 3) {
const results = [];
for (let p = 1; p <= n; p++) results.push(...(await search(q, { page: p })).organic);
return results;
}
Each page is a separate billed request. Keep your API key server-side — never ship it to the browser.
Next
- Google Search API for AI agents (LangChain/RAG)
- No-code with n8n / Make / Zapier
- Other languages: Python · PHP · Go
Try serp.cheap
Everything above runs on Node 18+ with zero dependencies. 100 free searches on signup — no card required; pay-as-you-go from $0.75/1k after that, and credits stay valid for 12 months.
- Get your free API key →
- Prefer paying by card? serp.cheap is also on RapidAPI (
$0.90/1k) and Apify ($1.50/1k).