Skip to content

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:

Terminal window
brew install ngrok

The 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:

Terminal window
ngrok help

Connect the agent to your account

  1. Sign up for an ngrok account.

  2. Copy your authtoken from the Your Authtoken page of the dashboard.

  3. 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:

Terminal window
ngrok http 8080

If it speaks HTTPS, give the full address so that ngrok connects to it with TLS:

Terminal window
ngrok http https://localhost:8080

A full HTTP address works as well:

Terminal window
ngrok http http://localhost:8080

ngrok 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.

References

Related notes

2 min read

NetBeans

Build Apache NetBeans from source, clear the Recent Projects list and choose the JDK the IDE runs on.

  • Developer Tools
3 min read

Vim and Neovim

Set up Vim with VimTeX and Zathura for LaTeX on macOS, and add the Neo-tree file explorer to Neovim.

  • Developer Tools
3 min read

SonarQube

Run SonarQube locally in Docker and analyse a Maven project with the SonarScanner for Maven.

  • Observability & Testing
  • Developer Tools

Type to search the whole site.