ngrok
Expose a local web server on a public HTTPS address with ngrok, for webhook testing, demos and testing on real devices.
2 min readUpdated
ngrok forwards traffic from a public HTTPS address to a service running on your machine. The ngrok agent opens an outbound connection to ngrok’s servers, so it works behind NAT and firewalls without opening ports. Typical uses are receiving webhooks from a payment or chat provider during development, showing work in progress to someone else, and testing a mobile app against a local backend.
Install the agent
On macOS with Homebrew:
brew install ngrokThe ngrok quick start also gives an apt repository for Debian and Ubuntu, and a Microsoft Store package for Windows. Older instructions used the tap ngrok/ngrok/ngrok.
Check the installation; ngrok prints its help text:
ngrok helpConnect the agent to your account
-
Sign up for an ngrok account.
-
Copy your authtoken from the Your Authtoken page of the dashboard.
-
Save the token in the agent’s configuration file:
Terminal window ngrok config add-authtoken ACCESS_TOKEN
The token is written to ngrok.yml, which lives in ~/Library/Application Support/ngrok/ on macOS and ~/.config/ngrok/ on Linux. The NGROK_AUTHTOKEN environment variable overrides it, which is useful in CI.
Expose a local service
If the local service speaks plain HTTP, give only the port:
ngrok http 8080If it speaks HTTPS, give the full address so that ngrok connects to it with TLS:
ngrok http https://localhost:8080A full HTTP address works as well:
ngrok http http://localhost:8080ngrok prints the public forwarding address and keeps running until you stop it with Ctrl+C. Visitors always reach the public address over HTTPS, with a certificate that ngrok manages. Every account has a dev domain that ngrok uses automatically; with --url you can choose another domain registered in your account, for example ngrok http 8080 --url https://api.example.com.
While the agent runs, its local inspection interface at http://127.0.0.1:4040 shows every request and response, and can replay a request, which helps when debugging webhooks.