avatarGautam Rajeev Singh

Summary

The web content provides a guide on using ngrok to expose multiple local host ports to the internet, which is particularly useful for developers needing to share their local development environment with others.

Abstract

The article titled "ngrok — Expose multiple local host ports to the internet" explains how developers can use ngrok, a cross-platform application, to make their local server ports accessible over the internet. The author, who uses Windows, outlines the steps to download and set up ngrok, including the use of an authentication token and the command to expose a specific port (e.g., port 8000). The article also addresses the limitations of ngrok's free-tier account, which typically allows only one port to be exposed at a time, and provides a workaround for exposing multiple ports simultaneously by editing the ngrok.yml configuration file. The author concludes by showing the terminal output after successfully making multiple ports live and provides additional resources for readers to explore ngrok's capabilities further.

Opinions

  • The author believes that ngrok is a valuable tool for developers who need to test their code and share their local development environment with peers or testers.
  • There is an acknowledgment of ngrok's paid features, but the author focuses on providing a solution using the free-tier account, suggesting a cost-effective approach for developers.
  • The author implies that the ability to expose multiple ports is not commonly known among ngrok users, indicating that this information could be a helpful tip for many developers.
  • By providing a step-by-step guide and screenshots, the author conveys a user-friendly approach to using ngrok, potentially making the tool more accessible to a broader audience.
  • The author encourages further exploration of ngrok's features by pointing readers to the official documentation, suggesting that there is more to learn beyond the scope of the article.

ngrok — Expose multiple local host ports to the internet

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:

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.

Ngrok
Command Line
Bash
Yaml
Recommended from ReadMedium