In developing an app where I needed to have a public URL on the web, I came across Ngrok. Ngrok is a useful utility, which provides a publicly accessible web URL to any locally hosted application. In my case, a nodejs web app. It also has authentication for secure tunnel access.
As the official site states, you can:
- Run personal cloud services from your home
- Demo websites without deploying
- Build webhook consumers on your dev machine
- Test mobile apps connected to your locally running backend
- Stable addresses for your connected devices that are deployed in the field
How it Works
Run the local app, so that it can be accessed at your localhost. Example: http://localhost:3000
Now with ngrok executable (available for different platforms like Mac, Windows, etc.) initiate a tunnel to the localhost on the desired port. We will see this detail in the upcoming sections.
Once ngrok sets up the tunnel, it provides a web-accessible URL.
Now share the publicly accessible url with the end-users who would hit the locally hosted application.
End users hit the web URL on the internet.When the request arrives at the ngrok server (As the URL is in a subdomain of ngrok.com the requests will initially land to ngrok server), and it will resolve the URL to the app that it needs to tunnel to.
Ngrok forwards the request to the tunnel created in Step 2.
The forwarded request connects to the locally hosted app.
Installation
Create a free account on Ngrok to get an auth token for your account.
Download client library depending on your operating system.
Unzip the downloaded package.
Update the ngrok configuration file with your auth token by running
./ngrok authtoken {your-auth-token}
command on the terminal/command prompt.After auth token gets updated, start the tunnel for your locally hosted applications.
Run
./ngrok http 80
command to start the tunnel on port 80 for localhost. An application running on this port is accessible through the tunneled https URL.
There are more features that you can do with Ngrok that you can read about on their official site.
References
Top comments (0)