serp.cheap का उपयोग करके Node.js से Google को क्वेरी करें और संरचित JSON प्राप्त करें। Node 18+ में fetch बिल्ट-इन है — किसी डिपेंडेंसी की ज़रूरत नहीं।
न्यूनतम उदाहरण
const res = await fetch("https://api.serp.cheap/v1/search", {
method: "POST",
headers: { "X-API-Key": "YOUR_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);
रिट्राई के साथ एक छोटा हेल्पर
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" });
पेजिनेशन
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;
}
प्रत्येक पेज एक अलग बिल किया जाने वाला अनुरोध है। अपनी API कुंजी को सर्वर-साइड रखें — इसे कभी ब्राउज़र में न भेजें।
आगे
- AI एजेंट्स के लिए Google Search API (LangChain/RAG)
- n8n / Make / Zapier के साथ नो-कोड
- अन्य भाषाएं: Python · PHP · Go