Setting up a Tor Proxy

The most stable way of doing this is to run a Tor proxy ourselves and redirect our Node.js requests through it. Setting up your own proxy sounds complicated but it’s easy. I’ll explain an easy way and a not so easy way of doing this. Both are relatively simple so bear with me.

Usually, when you install software like a proxy, the process is different depending on which operating system you’re running. Installing and configuring on Mac server would be different from a Linux server, so doing both would require repetitive efforts. This is what I call the not so easy way and it will be explained later. Now, let’s explain the cross-platform way.

Easy way

As mentioned above, the easy way is to install and configure Tor cross-platform using Docker. Docker is a containerization solution that lets you run your software inside a virtual-machine-like environment to isolate it from external interference. It also allows you to run your software in a managed environment so that you can reliably and easily run it cross-platform.

If you don’t already have Docker, install the correct community edition for your operating system here. After installing and starting it, we’ll run the Docker version of Tor proxy in our machine. Thankfully, someone took the time to set it up inside a Docker container and open-sourced it. We just need to run the image they published. Run this command below on your favorite shell/terminal:

docker run -it -p 9050:9050 -d dperson/torproxy

This command downloads the dperson/torproxy image from the public Docker Hub and runs it locally on your Docker setup. It also exposes this proxy on port 9050 so you can connect your scripts to the proxy over this port.

Not so easy way

If you’ve already set up Tor on the previous step, you can skip this one. I’ll explain how to do it without using Docker.

To set up Tor without using Docker, we need to install it manually.

For Ubuntu/Debian

To install Tor on Ubuntu/Debian, we need to update the source list of apt and then install Tor with apt . There are slight differences depending on the version of the operating system you're using. Tor Project already has a document with the steps and the exact code you need to run based on your operating system. Instead of repeating that information here, I recommend you take a look at their document here.

For Mac OSX

It’s easier for OSX compared to Linux distributions. There are two popular package managers for Mac, Homebrew and Macports. Install one of them if you haven’t already. If you don’t know which one to choose, I can recommend Homebrew as I’m quite satisfied with it:

Depending on which package manager you chose to install, run either:

brew install tor

or

sudo port install tor

Running Tor without Docker

Luckily this part is very simple. Simply run:

tor

Or, to run it in the background:

tor &