DEV Community

Stephano Kambeta
Stephano Kambeta

Posted on

How to Set Up HTTP Server + LocalTunnel for Web Development in Termux

If you’re a web developer or just learning, testing your projects on Android can be surprisingly easy with Termux. Instead of relying on a PC or cloud server, you can run an HTTP server directly on your device and even make it accessible online using LocalTunnel. This setup is perfect for previewing your websites, testing APIs, or sharing work with clients without installing heavy software.

Why Use Termux for Web Development?

Running an HTTP server on Android with Termux is lightweight, portable, and fast. You don’t need a laptop to test your HTML, CSS, or JavaScript projects. Plus, combining it with LocalTunnel lets you expose your local server to the internet temporarily, making remote demos simple and secure.

If you’re new to Termux or want to expand your skills, check out my guides on quick Termux projects and running Nginx in Termux for more web development options.

Requirements

  • Termux installed on your Android device (installation guide)
  • Basic HTML/CSS/JS project ready to test
  • Node.js and npm installed in Termux
  • Internet connection for LocalTunnel
  • Optional: knowledge of cybersecurity basics to keep your server secure (cybersecurity plan)

Step 1: Install Node.js and LocalTunnel

Open Termux and run the following commands:

pkg update && pkg upgrade -y
pkg install nodejs git -y
npm install -g localtunnel

Enter fullscreen mode Exit fullscreen mode

Node.js allows you to run HTTP servers with JavaScript tools, and LocalTunnel will make your local server accessible online. Using npm, LocalTunnel can be installed globally so you can use it anywhere in Termux.

Step 2: Start a Simple HTTP Server

Navigate to the folder containing your web project:

cd /sdcard/Download/my-website

Enter fullscreen mode Exit fullscreen mode

Then start a simple HTTP server using Node.js:

npx http-server -p 8080

Enter fullscreen mode Exit fullscreen mode

This command will serve your website locally on port 8080. You can now preview it in your Android browser by visiting http://localhost:8080.

Step 3: Expose Your Server with LocalTunnel

To share your site online temporarily, use LocalTunnel:

lt --port 8080

Enter fullscreen mode Exit fullscreen mode

LocalTunnel will generate a URL like https://randomname.loca.lt that you can share with anyone. They can access your local site instantly, without complex port forwarding or hosting setups.

If you want to make your server more secure, consider reading my post on using VPNs with Termux to hide your IP while exposing LocalTunnel URLs.

Step 4: Automate Server Startup

For convenience, you can create a simple script to start both the HTTP server and LocalTunnel automatically:

# create a file called start_server.sh
#!/bin/bash
cd /sdcard/Download/my-website
npx http-server -p 8080 &
lt --port 8080

Enter fullscreen mode Exit fullscreen mode

Make the script executable:

chmod +x start_server.sh
./start_server.sh

Enter fullscreen mode Exit fullscreen mode

Now, with one command, your site is live locally and online via LocalTunnel.

Step 5: Tips for Web Dev on Termux

  • Keep projects organized in dedicated folders inside Termux storage.
  • Use Termux automation scripts for repetitive tasks.
  • Test websites on both Android browser and PC using the LocalTunnel URL for cross-device compatibility.
  • Always monitor exposed URLs and shut down LocalTunnel when not needed to avoid security risks (network security tips).

Step 6: Advanced Options

You can combine this setup with Nginx for a more permanent server solution, or even integrate it with Python Flask apps for dynamic web development. Check out my guide on installing and using Nginx in Termux for advanced web hosting.

Wrapping Up

Using Termux to run an HTTP server with LocalTunnel is a lightweight, portable solution for web development on Android. It’s perfect for testing projects, showing clients your work, or experimenting with coding on the go. With this setup, your Android device can become a fully functional web server—private, flexible, and easy to manage.

For more ideas to extend your Termux capabilities, explore my quick Termux projects guide and take your Android web development to the next level.

Top comments (0)