{"id":13248,"library":"google-trends-api","title":"Google Trends Unofficial API for Node.js","description":"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.","status":"active","version":"4.9.2","language":"javascript","source_language":"en","source_url":"https://github.com/pat310/google-trends-api","tags":["javascript","google","trends","API","keyword","search","google-trends"],"install":[{"cmd":"npm install google-trends-api","lang":"bash","label":"npm"},{"cmd":"yarn add google-trends-api","lang":"bash","label":"yarn"},{"cmd":"pnpm add google-trends-api","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The library exports a default object containing all API methods. Named imports for individual methods are not supported.","wrong":"import { interestOverTime } from 'google-trends-api';","symbol":"googleTrends","correct":"import googleTrends from 'google-trends-api';"},{"note":"CommonJS require syntax for Node.js applications.","symbol":"googleTrends","correct":"const googleTrends = require('google-trends-api');"},{"note":"While callbacks are supported, the documentation encourages Promise-based usage for modern async/await patterns. If no callback is provided, a Promise is returned.","wrong":"googleTrends.interestOverTime({...}, callback);","symbol":"interestOverTime","correct":"await googleTrends.interestOverTime({...});"}],"quickstart":{"code":"import googleTrends from 'google-trends-api';\n\nasync function fetchTrendsData() {\n  try {\n    // Fetch interest over time for a keyword\n    const interestResults = await googleTrends.interestOverTime({\n      keyword: 'JavaScript Frameworks',\n      startTime: new Date('2023-01-01'),\n      endTime: new Date('2024-01-01'),\n      geo: 'US',\n      property: 'web'\n    });\n    console.log('Interest Over Time:', JSON.parse(interestResults));\n\n    // Fetch daily trending searches\n    const dailyTrends = await googleTrends.dailyTrends({\n      geo: 'GB',\n      // A date can be provided, otherwise it defaults to today\n      // date: new Date('2024-04-18')\n    });\n    console.log('Daily Trends (UK):', JSON.parse(dailyTrends));\n\n    // Get autocomplete suggestions for a partial keyword\n    const autoComplete = await googleTrends.autoComplete({ keyword: 'serverless' });\n    console.log('Autocomplete Suggestions:', JSON.parse(autoComplete));\n\n  } catch (err) {\n    console.error('Error fetching Google Trends data:', err);\n  }\n}\n\nfetchTrendsData();","lang":"typescript","description":"Demonstrates fetching interest over time, daily trends, and autocomplete suggestions using the library's Promise-based API methods."},"warnings":[{"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.","message":"Version 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.","severity":"breaking","affected_versions":">=4.0.0"},{"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.","message":"This 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"As `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.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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.","cause":"The library is being executed in a web browser environment, which is blocked by Google's CORS policies.","error":"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."},{"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.","cause":"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).","error":"Error: Invalid `keyword` parameter. `keyword` must be a string or an array of strings."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null}