ngrok — Expose multiple local host ports to the internet

Gautam Rajeev Singh
3 min readMay 13, 2022

--

Every developer is the first tester of his own code. And when working with a team, there can be instances when you would want to make your local host live to the internet for your peers to utilize it. This is just one of the many use cases. But if you are a developer, then you must have had a thought to make a port on your machine live. Well, ngrok is a tool for exactly that. So, in brief, ngrok is a cross-platform application that exposes local server ports to the Internet.

NOTE — I am using Windows operating system for my purpose, but you

  1. You can download the ngrok using this link.
  2. If you are able to run the ngrok command on your terminal, directly jump to step 4, or else, once downloaded, extract the zip and open the file ngrok.exe (in Windows OS).
  3. If you have the auth token, use command
  4. Suppose you want to expose port 8000 from your localhost to the internet, then you would run the command
  5. Now your localhost is live and should see something similar to the following console UI in your terminal.
exposing single host with ngrok

You can find ngrok docs here.

Limitations of a free-tier account

There is a list of paid features (click here to know more), one of which includes exposing multiple localhost ports to the internet. Which basically means that you cannot make more than 1 port live at once using the free account. But it is not commonly known that there is a workaround for that, which we are going to learn now.

Making multiple ports live at once

ngrok also has a configuration file stored in your system. You can find your file somewhere with the name of ngrok.yml under the directory -

  • Linux ~/.config/ngrok/ngrok.yml
  • MacOS (Darwin) ~/Library/Application Support/ngrok/ngrok.yml
  • Windows C:\Users\<User>\.ngrok2\ngrok.yml

To know more about this, you can go here.

Suppose you need to make the port number 8000 and 9000 live, then make changes in ngrok.yml file like this:

ngrok.yml

After saving the file, run the following command:

ngrok start --all

This would bring up something like this in your terminal

exposing multiple hosts in ngrok

Now you have two ports being shared on the internet using two different urls.

Conclusion

Hope you found the blog helpful.

There are definitely more possibilities to explore. You can use the following links to dive deeper —

Originally published at https://singhgautam.hashnode.dev.

--

--