[ Web Proxy ]
URL:
Viewing: https://serpapi.com/integrations/javascript [Back]  [Original]

SerpApi: JavaScript Integration
SerpApi home [SerpApi home]
Pricing

Choose the plan that suits you best.

Easy Integrations

Start integration with your preferred language.

Features

Dive deeper into our advanced features.

Company

Explore company information and helpful guides.

Search API for JavaScript

SerpApi SDK for JavaScript and Node.js.

Get started for free

JavaScript

Official SDK installation

  • $
    npm install serpapi

Code to integrate

SerpApi for JavaScript/TypeScript

npm version [npm version] Deno version [Deno version] Build status [Build status] License [License] SerpApi Libraries [SerpApi Libraries]

Scrape and parse search engine results using SerpApi. Get search results from Google, Bing, Baidu, Yandex, Yahoo, Home Depot, eBay and more.

Coming from google-search-results-nodejs? Check out the migration document to find out how to upgrade.

Quick start

Node.js

npm install serpapi
# or if you prefer yarn
yarn add serpapi
const { getJson } = require("serpapi");
getJson({
  engine: "google",
  api_key: API_KEY, // Get your API_KEY from https://serpapi.com/manage-api-key
  q: "coffee",
  location: "Austin, Texas",
}, (json) => {
  console.log(json["organic_results"]);
});

Node.js with ES Modules (ESM) and top-level await

You will need to add "type": "module" to your package.json:

{
  "type": "module",
  // rest of package.json
}
import { getJson } from "serpapi";
const response = await getJson({
  engine: "google",
  api_key: API_KEY, // Get your API_KEY from https://serpapi.com/manage-api-key
  q: "coffee",
  location: "Austin, Texas",
});
console.log(response);

Deno

import { getJson } from "https://deno.land/x/serpapi/mod.ts";
const response = await getJson({
  engine: "google",
  api_key: API_KEY, // Get your API_KEY from https://serpapi.com/manage-api-key
  q: "coffee",
  location: "Austin, Texas",
});
console.log(response);

Features

Configuration

You can declare a global api_key and timeout value by modifying the config object. timeout is defined in milliseconds and defaults to 60 seconds.

All functions, other than getLocations, accepts an optional api_key and timeout that will take precedence over the values defined in config.

getLocations doesn't require an API key.

import { config, getJson } from "serpapi";

config.api_key = API_KEY;
config.timeout = 60000;

await getJson({ engine: "google", q: "coffee" }); // uses the API key defined in the config
await getJson({ engine: "google", api_key: API_KEY_2, q: "coffee" }); // API_KEY_2 will be used

Using a Proxy

Note: SerpApi handles proxies on its end you do not need to supply your own proxy to avoid blocks or CAPTCHAs. This option is only for users who need to route all outbound requests through a corporate or network proxy.

You can route requests through your own proxy by passing requestOptions with an HttpsProxyAgent instance. This can be done either globally through the config object or per-request in the parameters.

First, install the required package:

npm install https-proxy-agent
# or if you prefer yarn
yarn add https-proxy-agent

Then use it in your code:

import { config, getJson } from "serpapi";
import { HttpsProxyAgent } from "https-proxy-agent";

// Global configuration
config.requestOptions = {
  agent: new HttpsProxyAgent("http://proxy-server:port"),
};

// Or per-request configuration
await getJson({
  engine: "google",
  q: "coffee",
  requestOptions: {
    agent: new HttpsProxyAgent("http://proxy-server:port"),
  },
});

Pagination

Built-in pagination is not supported. Please refer to our pagination examples for a manual approach:

Functions

Table of Contents

getJson

Get a JSON response based on search parameters.

Parameters

Examples

// single call (async/await)
const json = await getJson({ engine: "google", api_key: API_KEY, q: "coffee" });

// single call (callback)
getJson({ engine: "google", api_key: API_KEY, q: "coffee" }, console.log);

getHtml

Get a HTML response based on search parameters.

Parameters

Examples

// async/await
const html = await getHtml({ engine: "google", api_key: API_KEY, q: "coffee" });

// callback
getHtml({ engine: "google", api_key: API_KEY, q: "coffee" }, console.log);

getJsonBySearchId

Get a JSON response given a search ID.

Parameters

Examples

const response = await getJson({
  engine: "google",
  api_key: API_KEY,
  async: true,
  q: "coffee",
});
const { id } = response.search_metadata;
await delay(1000); // wait for the request to be processed.

// async/await
const json = await getJsonBySearchId(id, { api_key: API_KEY });

// callback
getJsonBySearchId(id, { api_key: API_KEY }, console.log);

getHtmlBySearchId

Get a HTML response given a search ID.

Parameters

Examples

const response = await getJson({
  engine: "google",
  api_key: API_KEY,
  async: true,
  q: "coffee",
});
const { id } = response.search_metadata;
await delay(1000); // wait for the request to be processed.

// async/await
const html = await getHtmlBySearchId(id, { api_key: API_KEY });

// callback
getHtmlBySearchId(id, { api_key: API_KEY }, console.log);

getAccount

Get account information of an API key. https://serpapi.com/account-api

Parameters

Examples

// async/await
const info = await getAccount({ api_key: API_KEY });

// callback
getAccount({ api_key: API_KEY }, console.log);

getLocations

Get supported locations. Does not require an API key. https://serpapi.com/locations-api

Parameters

Examples

// async/await
const locations = await getLocations({ limit: 3 });

// callback
getLocations({ limit: 3 }, console.log);

Free Plan · 250 searches / month

Get started

They trust us

You are in good company. Join them.

APIs

About

Contact

Our Values SerpApi [SerpApi]

We value full transparency and painful honesty both in our internal and external communications. We believe a world with complete and open transparency is a better world.

Built with love in Austin, TX. 2026 SerpApi, LLC.


Web Proxy Viewer  |  New URL  |  Original Page