Creating a Private Tor Website with ReactJS and Node.js

July 16, 2024 (2mo ago)

Creating a Private Tor Website with ReactJS and Node.js

Technologies like Tor boost safety and privacy, but they shouldn’t make things less convenient. This article will show you how to set up your own hidden Tor service. Then, you’ll learn to run a website powered by ReactJS and Node.js on it while keeping your privacy intact. This method lets you have both anonymity and cutting-edge tech.

What we are going to do

For the purpose of this article, I will assume you use a fairly recent Ubuntu Desktop distribution. We will set up a hidden Tor website and serve it from your local machine. Setting up a hidden Tor website is rather straight forward :

  1. Download the Tor package

  2. Set up your hidden service

  3. Start your web server on the right port

Essentially that’s it. I will walk you through the details in the following sections.

Installing and Running Tor

To connect to the Tor network and to run services on it, you need to install the tor package

Run this command in your terminal to install tor package

sudo apt install tor

Once that completes, you cat set up your hidden service by editing /etc/tor/torrc file. In the location-hidden services section, add these two lines

HiddenServiceDir /var/lib/tor/my_hidden_service
HiddenServicePort 80 127.0.0.1:3000

This will set your service directory to /var/lib/tor/my_hidden_service , which we will need later. Now, all traffic destined for the hidden service on port 80 should be routed to your local machine on port 3000. Finally, restart the Tor service :

sudo /etc/init.d/tor restart

Your hidden service is now advertised and accessible via the Tor browser. You can get your onion address by issuing this command :

sudo cat /var/lib/tor/my_hidden_service/hostname

This will print the onion address that the Tor browser can open. Next, we will add a web server to this setup.

Installing and Setting Up Node.js + ReactJS

To serve a website with Node.js and ReactJS, you first need to install Node.js. Although Ubuntu provides Node.js packages in its repositories, we will use a more recent version from NodeSource :

curl -fsSL https://deb.nodesource.com/setup_20.x | sudo bash -
sudo apt-get install -y nodejs

Afterward, we need to install the ReactJS convenience script, ‘create-react-app’:

sudo npm install -g create-react-app

Next, we will create a new ReactJS project. Navigate to the folder where you want to place the project (create-react-app will generate a subfolder with the project’s name) :

create-react-app your-hidden-react-website

Now, everything is set up. The website includes default content, which you can modify by editing ‘src/App.js’. For now, we will leave it as is. To start the web service, run the following command from within the project’s folder:

npm start

By default, it runs on port 3000, which matches the port we configured for the hidden service.

Inspecting the Results

The website can be accessed locally via ‘http://localhost:3000/’ or through the Tor network using the Tor browser. For the latter, you need the onion address, which you can retrieve from the directory you previously defined in ‘torrc’ using this command:

sudo cat /var/lib/tor/my_hidden_service/hostname

Enter this address into the Tor browser to anonymously access your local website through the Tor network.

🎉 Congratulations, you just created your first hidden service!