node.jstor

How do I programmatically use tor


My tor is connected to 127.0.0.1:9051, Its said that it not an http proxy so how can I really connect to websites programmatically using it (preferably node.js)? (Trying to connect using http GET)

Like is there a specific way of sending requests?

Thanks in advance 🙏


Solution

  • You can use Axios for request and set proxy to TOR SOCKS proxy. Like below

    const axios = require('axios');
    const SocksProxyAgent = require('socks-proxy-agent');
    const proxyOptions = `socks5://$127.0.0.1:9050`;
    const httpsAgent = new SocksProxyAgent(proxyOptions);
    const baseUrl = 'https://example.com'
    const client = axios.create({baseUrl, httpsAgent});
    client.get('/something').then(res => res.data);