Port forwarding with Local Tunnel and ngrok
Port forwarding enables you to expose a local development server to the internet.
Whether you choose Local Tunnel or ngrok,
these tools can help when remote access for testing or demos is required.
This guide explains how to set up each solution and offers recommendations for different operating systems.
Prerequisites
Make sure you meet the following requirements before starting:
- For Local Tunnel, you need Node.js installed on your machine. You can follow the setup guide at the NodeJS guide.
Using Local Tunnel
Local Tunnel is an open-source Node.js tool that creates a tunnel from the public internet to a port on your local machine.
Installation
Open a terminal and install Local Tunnel globally using npm:
npm install -g localtunnel
Creating a Tunnel
Once installed, you can forward your local server with a simple command. For example, to expose port 3000:
lt --port 3000
Local Tunnel will generate a public URL that forwards traffic to your local server. You may optionally specify a subdomain (if available) for a more memorable address:
lt --port 3000 --subdomain mydevsite
When you no longer need the tunnel, interrupt the command (e.g., Ctrl+C).
Using ngrok as an Alternative
ngrok is a popular service that tunnels your local server and provides free monitoring and secure tunnels. The setup for ngrok differs slightly by platform.
Setup for Windows
-
Download the Windows version from https://ngrok.com/download.
-
Unzip the downloaded file and place the ngrok executable in a known directory.
-
Open Windows Terminal or Command Prompt and run:
Terminal window .\ngrok.exe http 3000
Setup for Linux
-
Download the Linux tar file from https://ngrok.com/download.
-
Extract it and move the executable to a directory in your PATH.
-
In your terminal, run:
Terminal window ./ngrok http 3000
Setup for macOS
-
Download the macOS version from https://ngrok.com/download or install it using Homebrew:
Terminal window brew install --cask ngrok -
Then run in your terminal:
Terminal window ngrok http 3000
ngrok will display a web interface URL (typically at http://127.0.0.1:4040
)
where you can monitor incoming traffic and inspect requests.