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

Step 1: Installation

Open the command prompt from admin and run below command:

choco install ngrok

or you can Download Ngrok from the official website: https://ngrok.com/download and install it.

Step 2: Connect to your Account

If you have already a account the you can connect to your existing account. If you don’t have then you can create a 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>

Alternatively, you can go to yaml file and edit it to provide your token.

For windows ngrok yaml file can be found here

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

Step 3: Start Ngrok

Then you can run below command to start the ngrok. Here, my app is listening on http://localhost:4200. if your app is listening in different url the provide the correct one.

ngrok http http://localhost:4200

Then run your app and check.

Creating Multiple Tunnel

Add following in your yaml file to run two tunnel.

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

Note multiple tunnel is not available for free plan.

Checking log

Sometimes you may get the error and require 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.

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

In 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.

Leave a Reply

Your email address will not be published. Required fields are marked *