JavaScript / TypeScript SDK
@serpcheap/sdk आधिकारिक JavaScript/TypeScript क्लाइंट है — Node 18+, शून्य निर्भरता (नेटिव
fetch), पूरी तरह से टाइप किया हुआ।
इंस्टॉल करें
Section titled “इंस्टॉल करें”npm install @serpcheap/sdkक्विकस्टार्ट
Section titled “क्विकस्टार्ट”import { SerpCheap } from "@serpcheap/sdk";
const client = new SerpCheap("YOUR_API_KEY");
const res = await client.search({ q: "best running shoes", gl: "us" });for (const r of res.organic) { console.log(`${r.position}. ${r.title} — ${r.link}`);}विकल्प
Section titled “विकल्प”const client = new SerpCheap("YOUR_API_KEY", { baseUrl: "https://api.serp.cheap", // default timeoutMs: 15000, // default maxRetries: 2, // retries on transient errors});पेजिनेशन
Section titled “पेजिनेशन”searchPages आपके लिए पृष्ठों पर इटरेट करता है (समावेशी from/to):
for await (const page of client.searchPages({ q: "coffee makers" }, 1, 5)) { console.log(`page ${page.page}: ${page.organic.length} results`);}त्रुटि प्रबंधन
Section titled “त्रुटि प्रबंधन”import { SerpCheapError } from "@serpcheap/sdk";
try { const res = await client.search({ q: "query" });} catch (err) { if (err instanceof SerpCheapError) { console.error(`[${err.code}] ${err.message} (retryable=${err.retryable})`); }}