Tuesday, November 5, 2024

ngrok Tutorial: Guide to Creating Secure Tunnels to Localhost

Every developer knows that testing your web applications on localhost is an essential part of the development process. However, sometimes you might want to share your work with a colleague or test your webhooks. This is where ngrok comes in handy. Ngrok is a multi-platform tunneling, reverse proxy software that establishes secure tunnels from a public endpoint such as the internet to a locally running network service. This article provides a step-by-step tutorial on how to use ngrok effectively.

What is ngrok?

ngrok is a fantastic tool for developers, especially those working on webhooks and callback APIs. It creates a secure public URL (https://yourapp.ngrok.io) for exposing your local web server. With ngrok, you can demonstrate your local development to clients, colleagues, or anyone in the world without deploying it.

For a deep dive into the benefits and uses of ngrok, check out this comprehensive article here.

How to Install ngrok

Step 1: Download ngrok

First, download ngrok. Navigate to the ngrok download page and download the version compatible with your operating system.

Step 2: Unzip the Downloaded File

Once the download is complete, you need to unzip the file. For Windows, you can use the built-in extraction tool. On MacOS or Linux, you can use the terminal and navigate to the download directory and run the command unzip /path/to/ngrok.zip.

Using ngrok

Step 3: Connect your Account

Before you can start using ngrok, you need to connect your account. To do this, sign up on the ngrok website. After signing up, you will receive an auth token. Connect your account by typing in the terminal: ./ngrok authtoken YOUR_AUTH_TOKEN.

Step 4: Start a HTTP Tunnel

To start a HTTP tunnel on port 80 (replace with your port number if different), use the command ./ngrok http 80. Your localhost is now publically accessible from the URL provided by ngrok (https://randomstring.ngrok.io).

Tips for ngrok Usage

  • You can use the -region option to specify servers in the United States (us), Europe (eu), Asia (ap), Australia (au), or South America (sa). For instance, ./ngrok http -region=eu 80.
  • For more advanced usage, like password protection, custom subdomains, or multiple tunnels, you’ll need a paid ngrok account.

With this simple ngrok tutorial, you can now expose your local web server to the internet with ease and security. For any further queries, refer to the official ngrok documentation.

This tutorial is part of our series on useful tools for developers. Stay tuned for more tips and tutorials to enhance your development process.

Related Articles

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles