This tutorial will walk you through the process of using the Ngrok tool to make your local application available on the internet in a secure manner, restricted to your access. It is presumed that you have a functioning application on your local machine.
Installation Process
You can install Ngrok on various operating systems:
- For Mac OS:
- For Debian Linux:
- For Windows:
Use the command brew install ngrok/ngrok/ngrok
for a quick installation on Mac OS devices.
Alternatively, if the above methods are not suitable, download the Ngrok agent from the official download page.
The Ngrok agent is a stand-alone command-line tool compatible with all major operating systems. Verify your installation by typing ngrok help
in your terminal. This command should display Ngrok's help information to verify that it is installed successfully.
Linking Your Account
Now, you'll need to connect your Ngrok agent to your Ngrok account. If you don't have an Ngrok account yet, sign up first. Retrieve your Ngrok auth token from the dashboard of your account.
To connect your Ngrok agent with your account, input the following in your terminal, replacing <TOKEN>
with your actual auth token.
ngrok config add-authtoken <TOKEN>
Go Online
To start Ngrok and make your app accessible, run this command:
ngrok http http://localhost:8080
This command is based on the assumption that your web application is running on http://localhost:8080. If your application is hosted on a different URL, adjust the command accordingly.
Once you execute this command, your terminal will display an interface similar to this:
ngrok (Ctrl+C to quit)
Session Status online
Account [Your Account] (Plan: Free)
Version 3.0.0
Region United States (us)
Latency 78ms
Web Interface http://127.0.0.1:4040
Forwarding https://[unique-id].ngrok-free.dev -> http://localhost:8080
Connections ttl opn rt1 rt5 p50 p90
0 0 0.00 0.00 0.00 0.00
You can now access your web application by visiting the provided Forwarding URL.
This URL is publicly accessible. To test it, you can share it with others. Your app will be securely available over HTTPS, complete with a valid certificate, which Ngrok automatically provides.
Consistent Domain
If you prefer a consistent URL each time you launch your application with Ngrok, set up a static domain through your dashboard. Use the --domain
flag to specify your chosen domain when starting Ngrok. First, terminate the current Ngrok session with Ctrl+C
, then start it again with your static domain:
ngrok http 8080 --domain your-custom-domain.ngrok-free.app
Conclusion
Congratulations! You've successfully set up Ngrok and exposed your local web server to the internet. You can now use this powerful tool to test your applications and APIs during development.