# Google Trends API in JavaScript: extract Google Trends data from Node.js

> The Google Trends API runs from Node.js with the apify-client package: call the Actor kwerix/google-trends-api with a keyword list, then list the items of the run's dataset. A single HTTP call to the run-sync endpoint does the same with fetch, and the Apify API accepts browser requests, so a front end can run it with the user's own token.

Canonical: https://kwerix.com/trends/javascript/

## How to call the Google Trends API from Node.js

There are 4 steps to call the Google Trends API from Node.js.

1. **Install** the client with `npm install apify-client`.
2. **Set** your Apify API token in the `APIFY_TOKEN` environment variable.
3. **Call** the Actor `kwerix/google-trends-api` with the keywords and a location.
4. **List** the items of the run's dataset, one row per keyword.

```javascript

const client = new ApifyClient({ token: process.env.APIFY_TOKEN });
const run = await client.actor("kwerix/google-trends-api").call({
  keywords: ["sunscreen", "retinol"],
  geo: "US",
});
const { items } = await client.dataset(run.defaultDatasetId).listItems();
for (const row of items) console.log(row.keyword, row.seasonality?.publishBy, row.breakoutQueries.slice(0, 3));
```

## How to call the Google Trends API with plain HTTP

The Google Trends API answers one HTTP call on the run-sync endpoint, which runs the Actor and returns the rows for runs under 5 minutes. `maxTotalChargeUsd` in the query string caps the cost of the run.

```javascript
const res = await fetch(
  "https://api.apify.com/v2/acts/kwerix~google-trends-api/run-sync-get-dataset-items?maxTotalChargeUsd=0.5",
  {
    method: "POST",
    headers: { "Content-Type": "application/json", Authorization: `Bearer ${process.env.APIFY_TOKEN}` },
    body: JSON.stringify({ keywords: ["sunscreen", "retinol"], geo: "US", timeRange: "today 5-y" }),
  },
);
const rows = await res.json();
```

## How to get Trending Now data in JavaScript

Trending Now data in JavaScript takes the same call with `mode` set to `trending` and a list of countries, and returns one row per trend with its volume bucket.

```javascript
const run = await client.actor("kwerix/google-trends-api").call({
  mode: "trending",
  trendingGeos: ["US", "GB"],
  trendingHours: "24",
});
```

## Google Trends API vs the npm package google-trends-api

The Google Trends API and the npm package google-trends-api differ in how they reach Google Trends.

| Criterion | npm google-trends-api | Kwerix Google Trends API |
|---|---|---|
| Runs | In your Node.js process | As a hosted Apify Actor |
| Last release | December 28, 2020 | Maintained |
| 429 handling | In your code | Retries on a fresh session with proxies |
| Output | Google Trends responses as JSON text | One summarized row per keyword |

## Google Trends API in JavaScript FAQ

## Frequently asked questions

### Can I call the Google Trends API from the browser?

Yes. The Apify API accepts cross-origin requests with an Authorization header, so a page can call it with the visitor's own token; a shared token belongs on a server, never in front-end code.

### Is the npm package google-trends-api the same thing?

No. The npm package google-trends-api is an unofficial library last published on December 28, 2020 that reads Google Trends directly from Node.js, while the Kwerix Google Trends API runs as a hosted Actor.

## Sources

- [Kwerix, Google Trends API examples: JavaScript and cURL (GitHub, MIT license)](https://github.com/Kwerix/google-trends-api)
- [Apify API reference, run Actor synchronously and get dataset items (CORS checked September 30, 2026)](https://docs.apify.com/api/v2)
- [npm, google-trends-api package page (Google search result, captured September 30, 2026)](https://www.npmjs.com/package/google-trends-api)
