What is Ngrok and How to Use it?

What is Ngrok?

Ngrok is a cross-platform, open-source tool that provides secure tunnels from a public endpoint to a locally running network service. It is commonly used by developers to expose a web server, application, or service that is running on their local machine to the public internet. Ngrok simplifies the process of making your locally hosted services accessible externally without the need for complex networking configurations or firewall adjustments.

How to Use Ngrok for Windows Machine

Step 1. Installation

Open the command prompt from admin and run the below command.

choco install ngrok

Command Prompt

Alternatively, you can Download Ngrok from the official website here and install it.

Step 2. Connect to your Account

If you already have an account, you can connect to your existing account. If you don’t have one, then you can create one.

You can sign up for an account from here and then get your authentication token from your dashboard.

Once you have your authtoken, then run the below command in your terminal to install the authtoken and connect the Ngrok agent to your account.

ngrok config add-authtoken <YOURTOKEN>

On the other hand, you can go to the yaml file and edit it to provide your token.

For Windows machines, the ngrok yaml file can be found here

%HOMEPATH%\AppData\Local\ngrok\ngrok.yml

Step 3. Start Ngrok

Then, you can run the below command to start the ngrok. My app is listening here on http://localhost:4200. If your app is listening in a different URL, provide the correct one.

ngrok http http://localhost:4200

NGROK

Then, run your app and check.

Creating Multiple Tunnel

Add the following in your yaml file to run two tunnels.

tunnels:
web1:
 proto:http
 addr:4200
 web2:
  proto:http
  addr:7247

Note multiple tunnels are not available for the free plan.

Checking log

Sometimes, you may get the error and be required to check the log. So, for this, we can check the log in Ngrok itself.

Note to check the log. Your Ngrok should be running. Then you can go to ngrok – Inspect in the browser and see the logs as shown below.

POST NGROK

Ngrok can be used to expose web servers, REST APIs, or any service running on your local machine. It’s particularly useful during development and testing, as it allows you to share your work with colleagues or test it on various devices without deploying it to a public server.

Keep in mind that the free version of Ngrok comes with limitations, such as a random subdomain and a limited number of connections. For more advanced features and a custom subdomain, you may consider a paid Ngrok subscription.

Remember that while Ngrok is great for development and testing, using it for production services might not be as secure or efficient as deploying your application to a production server. Be cautious about exposing sensitive services through Ngrok or any similar tunneling service.

Conclusion

Ngrok serves as an indispensable tool in the developer’s toolkit, streamlining the process of exposing locally hosted services to the public internet. With its user-friendly setup and secure tunneling capabilities, Ngrok simplifies the task of sharing and testing web applications, APIs, and services during development.

Its versatility extends to a wide range of use cases, from web development and API testing to troubleshooting network issues. Ngrok’s free version provides a quick and convenient solution, while paid options offer greater customization and additional features.

While Ngrok is an invaluable asset for development and testing, it’s important to use it judiciously. Sensitivity to security and data protection is essential when sharing services via Ngrok. As with any tool, it should be employed with a clear understanding of its limitations and potential risks. In the ever-evolving landscape of web development, Ngrok remains a go-to solution for easily and securely connecting local services to the world, making the development process more efficient and collaborative.

References