Registry / data / google-trends-api

google-trends-api

JSON →
library2.2.6jsnpmunverified

This library provides an unofficial API layer for programmatically accessing Google Trends data, primarily designed for server-side (Node.js) environments to bypass client-side CORS restrictions. It enables developers to query various Google Trends endpoints such as interest over time, daily trends, related queries, and autocomplete suggestions. The current stable version is 4.9.2, and the project is actively maintained with ongoing expansions and improvements. A key differentiator is its ability to access Google Trends data without requiring an official Google API key, by mimicking web requests to the public Google Trends interface. It supports both traditional callback functions and modern Promise-based patterns for asynchronous operations, returning parsed data in a structured JavaScript object format.

npm install google-trends-api
INSTALL
IMPORT
SIG · GOOGLE-TRENDS-API
G
google-trends-api
datajavascriptv2.2.6
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

googleTrends
import googleTrends from 'google-trends-api';
import { interestOverTime } from 'google-trends-api';
The library exports a default object containing all API methods. Named imports for individual methods are not supported.
googleTrends
const googleTrends = require('google-trends-api');
CommonJS require syntax for Node.js applications.
interestOverTime
await googleTrends.interestOverTime({...});
googleTrends.interestOverTime({...}, callback);
While callbacks are supported, the documentation encourages Promise-based usage for modern async/await patterns. If no callback is provided, a Promise is returned.

Demonstrates fetching interest over time, daily trends, and autocomplete suggestions using the library's Promise-based API methods.

import googleTrends from 'google-trends-api'; async function fetchTrendsData() { try { // Fetch interest over time for a keyword const interestResults = await googleTrends.interestOverTime({ keyword: 'JavaScript Frameworks', startTime: new Date('2023-01-01'), endTime: new Date('2024-01-01'), geo: 'US', property: 'web' }); console.log('Interest Over Time:', JSON.parse(interestResults)); // Fetch daily trending searches const dailyTrends = await googleTrends.dailyTrends({ geo: 'GB', // A date can be provided, otherwise it defaults to today // date: new Date('2024-04-18') }); console.log('Daily Trends (UK):', JSON.parse(dailyTrends)); // Get autocomplete suggestions for a partial keyword const autoComplete = await googleTrends.autoComplete({ keyword: 'serverless' }); console.log('Autocomplete Suggestions:', JSON.parse(autoComplete)); } catch (err) { console.error('Error fetching Google Trends data:', err); } } fetchTrendsData();
Debug
Known issues
breakingVersion 4.0.0 introduced significant breaking changes. The underlying Google Trends endpoints used by previous versions (v3.x and earlier) were deprecated and heavily throttled, rendering them unreliable. Older versions are no longer actively supported and may fail to fetch data.
fix
Upgrade to `google-trends-api@^4.0.0` or later. Review the updated API methods and parameter structures outlined in the library's documentation, as direct replacements for older calls may not exist or function identically.
affects: >=4.0.0
gotchaThis library is designed for server-side execution within Node.js environments due to Google's Cross-Origin Resource Sharing (CORS) policies. Attempting to use `google-trends-api` directly in a web browser will result in CORS errors.
fix
Implement a Node.js backend or serverless function to make calls to `google-trends-api`. Expose the necessary Google Trends data through your own API endpoints for consumption by frontend applications.
affects: >=1.0.0
gotchaAs `google-trends-api` scrapes data from the public Google Trends interface, frequent or excessively rapid requests can lead to IP-based rate limiting or temporary blocking by Google. This is an inherent limitation when interacting with unofficial web scraping methods.
fix
Implement client-side caching for frequently requested data, introduce delays or throttling between API calls, or consider using a proxy server rotation strategy for high-volume data collection.
affects: >=1.0.0
Errors
Common errors & fixes
Access to fetch at 'https://trends.google.com/...' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
The library is being executed in a web browser environment, which is blocked by Google's CORS policies.
fix
Move the `google-trends-api` calls to a Node.js server or serverless function. Your frontend application should then call your custom backend API to retrieve the data.
Error: Invalid `keyword` parameter. `keyword` must be a string or an array of strings.
The `keyword` option, which is required for most API methods, was either missing or provided with an incorrect data type (e.g., a number or null).
fix
Ensure the `keyword` property in the options object is set to a string (for a single keyword) or an array of strings (for multiple keywords) before making the API call.
Upgrade
Version history
2.2.6latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
33 hits · last 30 days
node
30
Resources
google-trends-api — npm install google-trends-api · libregistry