JavaScript developer guide
Google Search API in JavaScript & Node.js
Use the Google Search API from JavaScript and Node.js with authentication, targeting, pagination, JSON parsing, timeouts, and robust error handling.
A complete Node.js request
Node 18 and later include fetch, so the example has no runtime dependencies. Keep the API key in an environment variable and never ship it in browser-side JavaScript.
search-google.mjs
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), 30_000);
try {
const response = await fetch("https://api.prismcrawl.com/v1/google/search", {
method: "POST",
signal: controller.signal,
headers: {
"x-api-key": process.env.PRISMCRAWL_API_KEY,
"content-type": "application/json",
},
body: JSON.stringify({
query: "best coffee shops",
gl: "us",
hl: "en-US",
location: "Austin,Texas,United States",
device: "mobile",
}),
});
if (!response.ok) {
throw new Error(`PrismCrawl returned ${response.status}: ${await response.text()}`);
}
const payload = await response.json();
for (const result of payload.data.content.results ?? []) {
console.log(result.rank, result.title, result.url);
}
} finally {
clearTimeout(timeout);
}Production integration checklist
- Call PrismCrawl from a trusted server—not the browser
- Use an AbortController timeout
- Handle non-2xx responses before parsing success data
- Retry transient 429/5xx responses with capped backoff
- Log request_id for debugging and support
- Read has_next_page before requesting another page
Pagination and response parsing
paginate.mjs
async function searchPage(query, start = 0) {
const response = await fetch("https://api.prismcrawl.com/v1/google/search", {
method: "POST",
headers: {
"x-api-key": process.env.PRISMCRAWL_API_KEY,
"content-type": "application/json",
},
body: JSON.stringify({ query, start, gl: "us", device: "desktop" }),
});
if (!response.ok) throw new Error(await response.text());
return (await response.json()).data.content;
}
for (let start = 0; ; start += 10) {
const data = await searchPage("site:example.com product", start);
data.results?.forEach(({ rank, url }) => console.log(rank, url));
if (!data.has_next_page) break;
}Test before you integrate
Build the request in the SERP API playground, inspect every field in the API reference, compare the Python implementation, and review the complete SERP API feature and pricing guide.
Make your first live search today.
Create an account, get 25 free credits, and test live Google or Bing results. No credit card or subscription required.