The google-search-results-nodejs
npm package is being deprecated in favor of
the serpapi
npm package. It will still be available via npm, but will not
receive feature updates. The following are the differences to better help you
migrate over to the serpapi
npm package.
-
Use functions rather than classes to access SerpApi. The
engine
parameter is used to specify the target search engine.// ❌ Previous way. import { GoogleSearch } from "google-search-results-nodejs"; const engine = new GoogleSearch(API_KEY); engine.json(...); // ✅ New way, import and use functions directly. import { getJson } from "serpapi"; getJson({ engine: "google", api_key: API_KEY, ... })
-
The
search_archive
method is replaced bygetJsonBySearchId
andgetHtmlBySearchId
.// ❌ Previous way, only supported JSON output. engine.search_archive(searchId, console.log); // ✅ New way, use `getJsonBySearchId`. getJsonBySearchId(searchId, { api_key: API_KEY }, console.log); // ✅ New way, use `getHtmlBySearchId` if you want the HTML result. getHtmlBySearchId(searchId, { api_key: API_KEY }, console.log);
-
The
account
andlocation
methods are nowgetAccount
andgetLocations
. Theq
andlimit
parameters forgetLocations
are now optional.// ❌ Previous way, was part of the engine class. engine.account(console.log); engine.location("Austin", 5, console.log); // ✅ New way, functions not tied to a class. import { getAccount, getLocations } from "serpapi"; getAccount({ api_key: API_KEY }, console.log); getLocations({ q: "Austin" }, console.log);
- The
buildUrl
,execute
andsearch
methods are removed. UsegetJson
andgetHtml
functions instead. - The
SerpApiSearch
class is removed as a public class.
- TypeScript support.
- First-class Promises support.
const json = await getJson({ engine: "google", q: "coffee" });
config
object to configure globalapi_key
andtimeout
values.import { config } from "serpapi"; config.api_key = "new_api_key"; config.timeout = 20000; // 20 seconds
- Error classes (
MissingApiKeyError
,InvalidTimeoutError
andInvalidArgumentError
).getJson({ engine: "google", api_key: "" }); // Throws `MissingApiKeyError` getAccount({ api_key: API_KEY, timeout: 0 }); // Throws `InvalidTimeoutError` getJson("google"); // Throws `InvalidArgumentError`