Send Node.js web requests through Tor, with an optional “new identity” switch. Built with a modern, security-first approach.
GitHub: https://github.com/hrach347/tor-proxy-agent
npm install tor-proxy-agentimport tor from "tor-proxy-agent";
const { response, body } = await tor.request({url: "https://api.ipify.org",});
console.log(response.statusCode);
console.log(body);import tor from "tor-proxy-agent";
// ip, port, type (5 = socks5, 4 = socks4)
tor.setTorAddress("127.0.0.1", 9050, 5);
const { body } = await tor.request({ url: "https://api.ipify.org" });
console.log(body);import tor from "tor-proxy-agent";
await tor.newTorSession();
// Tor can rate-limit NEWNYM; waiting helps in practice.
await new Promise(r => setTimeout(r, 10_000));
const { body } = await tor.request({url: "https://api.ipify.org"});
console.log(body);Note:
SIGNAL NEWNYMrequests a new circuit, but it does not guarantee a new exit IP immediately.
If you use HashedControlPassword, set the ControlPort password for your app:
Create a .env file in your project:
TOR_CONTROL_PORT_PASSWORD=my_secret_password- Node.js >= 18
- Tor installed and running
- SOCKS port (default):
127.0.0.1:9050 - ControlPort (optional):
127.0.0.1:9051
- SOCKS port (default):
Debian/Ubuntu
sudo apt update
sudo apt install tor
sudo systemctl enable --now tormacOS (Homebrew)
brew install tor
torYour torrc is commonly located at one of:
- /etc/tor/torrc
- /usr/local/etc/tor/torrc
Generate the hash
tor --hash-password "my_secret_password"Put the hash into torrc
ControlPort 9051
HashedControlPassword 16:REPLACE_WITH_HASH_OUTPUTRestart tor
sudo systemctl restart torIf you want Tor running like a real local service (best for dev), use the Tor Expert Bundle.
Get Tor Expert Bundle from the official Tor Project website.
Extract it, then run tor.exe from a terminal (PowerShell / CMD).
Create/edit torrc and add:
SocksPort 9050
ControlPort 9051
CookieAuthentication 1
HashedControlPassword 16:REPLACE_WITH_HASH_OUTPUT
Note: create hash in Windows -
tor.exe --hash-password "my_secret_password"
If this package helped, drop a ⭐ on the repo.