DEV Community

Deven Sitapara
Deven Sitapara

Posted on

Expose Your Localhost to a Public URL

When developing a local application, you might want to share it with others remotely or test it on external devices. Here are three popular tools—ngrok, Localtunnel, and Cloudflare Tunnel—for creating a public URL for your local server.


1. Using ngrok

ngrok is a popular tool that creates secure tunnels, supporting HTTP, HTTPS, and TCP protocols.

Step 1: Install ngrok

  1. Visit ngrok’s official website and download the latest version of ngrok for your OS.
  2. Unzip the downloaded file and move the ngrok executable to a directory included in your system's PATH.

Step 2: Set Up ngrok Authentication

  1. Sign up on ngrok to get an authentication token (this is required for free users to use ngrok).
  2. Run the following command in your terminal:

    ngrok authtoken <your_auth_token>
    

Step 3: Start an ngrok Tunnel

  1. In your terminal, navigate to the directory where your local server is running.
  2. Run the following command (replace 3000 with your server’s port):

    ngrok http 3000
    
  3. You’ll see a public URL like https://<random_string>.ngrok.io in the terminal. Use this URL to access your localhost from anywhere.

Pros: Secure, widely used, supports multiple protocols.

Cons: Free version has a limited session time and random URLs.


2. Using Localtunnel

Localtunnel is a simple and free solution that requires minimal setup. It’s ideal for quickly sharing local apps temporarily.

Step 1: Install Localtunnel

  1. Make sure you have Node.js installed, as Localtunnel is an npm package.
  2. Install Localtunnel globally with this command:

    npm install -g localtunnel
    

Step 2: Start a Localtunnel Session

  1. Open your terminal and navigate to the directory where your local server is running.
  2. Run the following command (replace 3000 with your server’s port):

    lt --port 3000
    
  3. You’ll get a URL like https://<random_string>.loca.lt that you can share.

Pros: Easy setup, no registration required.

Cons: URLs are random; no advanced security features.


3. Using Cloudflare Tunnel (Argo Tunnel)

Cloudflare Tunnel (previously Argo Tunnel) is a secure way to expose your localhost, protected by Cloudflare’s security features. It’s great for long-term use.

Step 1: Install Cloudflare’s CLI Tool

  1. If you’re on macOS, run the following command to install Cloudflare’s CLI (cloudflared):For other operating systems, visit Cloudflare Tunnel’s documentation to find the appropriate installer.

    brew install cloudflared
    

Step 2: Start a Cloudflare Tunnel

  1. Run the following command to start a tunnel (replace 3000 with your server’s port):

    cloudflared tunnel --url http://localhost:3000
    
  2. Cloudflare will provide you with a public URL associated with your Cloudflare account.

Pros: Secure, reliable, and good for long-term access.

Cons: Initial setup can be slightly more involved.


Summary Table

Tool Installation Difficulty Security URL Type Best Use Case
ngrok Easy High Random (free) General, short-term sharing
Localtunnel Very easy Medium Random Quick, temporary use
Cloudflare Tunnel Moderate Very High Permanent (with account) Long-term, secure projects

Each tool offers unique advantages for sharing your localhost. Choose the one that best fits your needs, whether it’s a quick test or a more permanent, secure solution.

Key Takeaways of Using Tunneling Tools like above

Ease of Sharing Local Servers

  • Instantly share your development environment with external collaborators or testers without deployment.
  • Access your app using a secure, public URL.

Cross-Device Testing

  • Test locally hosted applications on external devices like phones, tablets, or other machines in different networks.
  • Ensure compatibility across multiple devices and environments.

Convenient Collaboration

  • Demonstrate app functionality to clients or stakeholders without deploying to a staging or production server.
  • Collaborators can interact with the live local app in real time.

Free to Start

  • All tools provide free tiers suitable for most personal and small-team use cases.
  • Cost-effective for occasional remote access needs.

Minimal Setup

  • Simple to install and run with minimal configuration, typically requiring just a single command to start.

Using tools like ngrok, Localtunnel, and Cloudflare Tunnel enables rapid prototyping, collaboration, secure testing, and integration debugging, all while saving time and effort during local app development. These tools eliminate deployment barriers, helping developers focus on building and testing features without worrying about infrastructure setup.


Top comments (1)

Collapse
 
devatsrs profile image
Deven Sitapara

Let me know your favourite tools