A situation where we need to expose our localhost to the internet world do exists. Just to mention a few: web development, API development, new product test, or just a for-fun project using new framework. It’s gonna be super fun when we can let people can see our ‘thing” running.
Meet ngrok, a secure tunnel to localhost. This is one of service that I found so useful lately. I don’t have to purchase a domain to share what I am doing to my colleague. One line of ngrok command and the magic happen.
So, that’s all the crappy talk. Let’s just do something.
Suppose we’re having a HTTP web server running on localhost:4000 on a 64 bit Ubuntu server.
Go to https://ngrok.com/download and choose the package based on your platform. In this case we will use Linux 64-bit packages. I am going to use wget as a sample.
Unzip it. You will see one executable file called ngrok.
Run it using below command.
./ngrok http 4000
It means we are using ngrok with HTTP protocol on port 4000. You will see something like this.
Now we can type http://05ae780c.ngrok.io on browser and see the app has been public.
Well, 05ae780c prefix is quite hard to remember, and if we stop running ngrok then rerun it, the prefix also going to be changed. To solve that problem we must upgrade ngrok to paid plan. ngrok shall give a reserved subdomain for paid account.
Conclusion, ngrok is a very helpful service even in a free service. At least we don’t have to worry on how to let the world see our localhost.