Sometimes you need to access a dev server running on localhost from another machine that is not part of the same network. Maybe you want to use your phone to test a web page, but are only in a guest WiFi. In the past, we often used some port forwarding or other techniques to expose the service to the internet.
Enter ngrok, a command line tool that gives you an on-the-fly internet domain routing to your localhost.
On ubuntu, you can install ngrok with sudo snap install ngrok
. Then start it using
ngrok http 3000
Now, if you open the http
or https
URL shown, you will reach your local machine on port 3000.
This can also be useful if you need to test with TLS, without having to jump through the hoops of creating some self-signed TLS certificate.
Note: Ngrok rate limits your requests, but to a reasonable level. They sell pro subscriptions for features like higher request limits, or custom URLs.
Warning
Shut it down after use. The URL is sufficiently random to not be guessable, but exposing your dev server to the internet is generally not the best idea.
In my tests I was not easily able to get a better errors console. It seems ngrok correctly indicates that requests came from a remote IP.
localtunnel
To be able to use ngrok you need an account! As alternative you can also use localtunnel Show archive.org snapshot .