Purpose
trendflow-js is a type-safe JavaScript/TypeScript library for querying and exporting Google Trends data, and is the JavaScript port of trendflow-py. Created by Dario Mory, it is released under the MIT license, requires Node.js 18+ (using the global fetch), and is published in ESM and CommonJS forms with type declarations.
Main capabilities
The library provides four main query methods, all asynchronous and returning a Promise:
- Interest over time
- Interest by region
- Trending now
- Related queries
Trending now supports two backends, RPC and RSS, selected via the backend parameter: the default "auto" first tries RPC and falls back to feed on failure. RPC returns five times as much information as RSS and includes real growth data, so RPC is preferred by default; choose "rss" when article links are needed. Although feed is formally a feed, it is not lighter—Google ignores its hours, sort, and count parameters and always returns the same 10 records.
The library distinguishes search terms (literal strings) from topics (entities). suggestions() is used to find topics, and all query methods already support topics—just pass the mid wherever a keyword is expected. Topics aggregate various phrasings and translations, so their scores can be much higher than literal phrases. suggestions() does not require cookies or a proxy and can respond on IPs that are rejected with 429 by the widgetdata endpoint, just like trendingNow(). The type field distinguishes entities with the same name (for example, "Nike" returns both the company and the goddess), and is null when Google omits it.
The time window for trending now can be selected via TrendingWindow; window is an undocumented Google parameter, of which two values have clear behavior, and other integers between 4 and 12 also return data for different recent windows, so raw numbers can be passed directly.
Usage
Install via npm: npm install trendflow (npm package URL:https://www.npmjs.com/package/trendflow)。
Google Trends enforces strict rate limiting on data centers and shared IPs; even the first request of the day may return 429. Two things to note: User-Agent (Google returns 429 for the default agent string of Node HTTP clients; this library sends a browser User-Agent by default; if you customize headers, keep it realistic) and IP reputation (once an IP is flagged, every request returns 429 regardless of headers, and recovery requires a residential proxy).
Proxy pool: pass in a set of proxy URLs, and the client will rotate automatically, switching to the next one when a query is rejected. Proxy support requires undici as an optional peer dependency: npm install undici. Rotation is per query, not per request—Google binds the NID cookie and widget token to the requesting IP, and a single query must be completed on one egress IP, otherwise subsequent widgetdata calls will immediately return 429. Therefore, the proxy pool should point to sticky sessions rather than per-request rotation endpoints. For errors that cannot be resolved by changing IPs (such as 404 or UnknownRpcError when Google renames the batchexecute RPC id), skip rotation. maxProxyAttempts is used to handle the case where a shared residential proxy pool is exhausted.
You can also pass in a custom fetch for logging, caching, or custom routing (mutually exclusive with proxies; if both are passed, the library will warn).
Browser / Next.js: all methods except export() can run in environments that support fetch, but Google Trends does not send CORS headers, and browser JavaScript calls will be blocked, so it should be used server-side (Route Handlers, Server Actions, API routes) and the results passed to the client.
MCP server: the library ships with a separate trendflow-mcp package, allowing agents to query Google Trends directly, while the library itself remains zero-runtime-dependency. It provides six tools (search_topics, get_interest_over_time, get_interest_by_region, get_related_queries, get_trending_now, research_trend) and two resources; see mcp/README.md for details.
Use cases
- Google Trends data fetching and export on the server side (Node.js, Next.js Route Handlers, Server Actions, API routes).
- Integration of trend data into JavaScript/TypeScript projects that need type safety.
- Scraping scenarios that evade Google Trends rate limiting through a proxy pool.
- Allowing agents such as ChatGPT, Claude, and Cursor to query Google Trends directly through trendflow-mcp.
Limitations and notes
- Requires Node.js 18+.
- Browser-side calls are not possible due to missing CORS headers; it must be used server-side.
- Proxy support depends on the optional undici.
- timeout uses milliseconds (JS convention), not seconds.
- Enums are as const objects; Region.US is the string "US", and any valid string literal can replace the type position.
- Except for InterestOverTimeResult, which is a class (with conversion methods), the results are interfaces.
- Higher-precision time series and keyword-dimension related queries require a reCAPTCHA Enterprise token, which this library does not implement; they can still be obtained through interestOverTime() and relatedQueries().
- Google has discontinued three endpoints—hottrends/visualize/internal/data, api/dailytrends, and api/realtimetrends (all now return HTTP 404)—and this library uses the batchexecute RPC instead.
- This RPC backend does not include article links; articles is empty, and you need to pass { backend: "rss" } to get news articles.
- Unit tests do not access the network; if you need to verify real endpoints, refer to the repository documentation.
- Regarding versions: currently trendflow-py 0.2.0 and trendflow 0.1.0; the two libraries are versioned independently.
Documentation:https://trendflow.mory.dev/docs/js;API References:https://dariomory.github.io/trendflow-js/;Python Sister libraries:https://pypi.org/project/trendflow-py/。