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