Access your local application from a public URL
Ngrok allows you to connect through a tunnel and navigate to your local application running on a publicly available endpoint
Imagine the following use case: you have your application up and running locally and someone (or some platform) needs to access it for some testing. Giving them the http://localhost:8080
application URL is not going to help, right? So how can you quickly provide a valid public URL for your localhost application? Let’s find out.
Table of contents
Glossary
- URL: Uniform Resource Locator
- VPS: Virtual Private Server
- DNS: Domain Name System
Ngrok
We all know that publishing a website is not an easy process, specially when you happen to still in the test phase of your app or is just running a cool playground and would like to showcase it to a friend. For hosting an application on the internet there’s quite a lot of configuration required such as purchasing a domain, registering DNS records pointing to the machine (usually a VPS) where you are hosting your application (in a cloud service provider like Digital Ocean, AWS or Azure). What if I tell you that ngrok is a tool that acn help you with that?
How?
Ngrok brand themselves as “secure introspectable tunnels to localhost”, which means they create a tunnel from your local host environment to their cloud/hosting service, giving the developer the ability to access a local application from a public available URL. Sounds like magic but it is not (it is technology baby).
Download ngrok
First of all you need to download ngrok here based on your operating system. Unzip the downloaded file into a directory and navigate to it - I have it on the root folder where all my coding projects are so I can quickly run it.
Register your account
This step is optional and if you don’t need to track your currently open tunnels, don’t need any configuration change for now or already have an account feel free to skip to the next step.
Signing up is simple, just click here and fill out their account registration form.
Once you are logged in, find your authentication token (from the left bar navigation menu go to Getting Started > Setup & Installation, check section 2. Connect your account
) and run from the ngrok directory the command:
ngrok authtoken %YOUR_AUTH_TOKEN%
Running ngrok
From the command line run the following command to start ngrok:
Replace
%PORT_NUMBER%
with the port you usually run your app on so all http/https requests received on your ngrok URL are forwarded to the right port on your local development environment.
ngrok http %PORT_NUMBER%
After running this command successfully you should see the details of your connection in the command line/terminal screen.
If you’re connected to the internet behind a proxy or firewall make sure ngrok is accessible from your network.
Tracing requests
Ngrok provides a useful tool for inspecting the requests received on your active tunnel. To do it so you can navigate to localhost:4040.
If you are authenticated check your ngrok.com tunnels dashboard.
More information
For finding out more capabilities check out their documentation.
Final Considerations
Ngrok makes it easy to access your local application from a public URL enabling developers to test a live application from their local environment with very little configuration.
Liked this tutorial? Don’t forget to leave comment and share word.
See ya! 👋