← 블로그로 돌아가기

Node.js에서 Google Search API 사용하기: 완전 튜토리얼 (2026)

Node.js / JavaScript에서 Google Search API 사용하기 — fetch 기반 요청, 비동기 페이지네이션, 재시도, 타입 헬퍼. serp.cheap로 바로 복사해 쓰는 예제.

1 분 소요

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 키는 서버 측에 보관하세요 — 절대 브라우저로 전송하지 마세요.

다음 단계

Frequently asked questions

Node.js에서 Google Search API를 어떻게 호출하나요?+

내장 fetch(Node 18+)를 사용해 쿼리를 POST하세요. serp.cheap의 경우: fetch('https://api.serp.cheap/v1/search', { method: 'POST', headers: { 'X-API-Key': KEY, 'Content-Type': 'application/json' }, body: JSON.stringify({ q, gl: 'us' }) }).

SDK가 필요한가요?+

꼭 필요하지는 않습니다 — SERP API는 단순한 HTTP 엔드포인트이므로 네이티브 fetch(또는 axios)면 충분합니다. 다만 serp.cheap은 타입 지정 호출, 재시도, 페이지네이션을 갖춘 공식 JavaScript/TypeScript SDK(npm install @serpcheap/sdk)와 함께 NestJS 및 Next.js 통합도 제공합니다.

API 키 받기

직접 구매가 가장 저렴, 카드 또는 암호화폐로 결제, KYC 불필요. 또는 마켓플레이스 이용.