Search code examples
node.jsresthttprequesttorgoogle-trends

Can I force a nodejs module to make requests through TOR without directly modifying the module?


I'm trying to use the google-trends-api npm module to pull down google trends historical data. This had been working fine for a week or two, but then all of the sudden last night I got rate limited hard, and now I can't any requests via either nodejs nor my browser. However, if I fire up TOR Browser and make a request it works just fine.

I found the tor-request npm module, and it seems like that would solve my problem just fine, except that its designed to be wrapped around individual requests. As the request occurs within the module I'm importing, and not directly in my own code, this means I would either need to dump or fork the module to make the tor-request module work.

Is there a way to force modules to make make their requests through TOR without modifying the actual module code? For example, something I can set at the start of my program that forces all normal requests through TOR. I had trouble finding an answer to this, since all searches directed me back to the tor-request module.

Not trying to abuse the Google Trends API, just trying to be able to use it at all again.


Solution

  • In addition to torify, I found that the module (google-trends-api) I was trying to route through TOR took an agent argument, which it just passes to a request, so I spun up a TOR proxy on my computer and passed the api module a socksProxyAgent, and it works fine.