Using ngrok to test local websites and APIs

Often when I am creating a new website, I want to see how it is going to look on an actual device like my phone or tablet. You can use Chrome Web Tools for mimicking a device but it isn’t the same as an actual phone.

However, chances are that if you try and access the service using your IP Address on another device it will likely be blocked by your operating systems firewall. If you want to share the website or API with someone not on your network, you need to jump through lots of hoops such as forwarding the port on your router.

This is where ngrok comes in. It allows you to expose your local service or website over a secure tunnel.

Installing Ngrok

Ngrok couldn’t be simpler to install.

  1. Head over to and sign up for an account (it’s free).
  2. Download ngrok for your operating system. They support Windows, Mac (Intel and Arm), Linux (Intel and Arm) and FreeBSD.
  3. Unzip the downloaded zip file
  4. Connect ngrok to your account ./ngrok authtoken <auth token here>

Using Ngrok

Once Ngrok is installed it is simple to use.

  1. First, start up your application so that it is running on your local machine. If I run this Gatsby website locally it runs on port 8000.
  2. Start a tunnel to your local port (8000 in this case) ./ngrok http 8000. You should see an output like this:

Ngrok gives you the HTTP and HTTPS address that you can connect to and you will see the incoming HTTP requests on the console.

From there you can access the service running locally on your phone, tablet or even give it to someone else to try out.

You can also access a Dashboard locally on port 4040 if you want to get a detailed look at the requests and responses going to your service.

Ngrok is free for single-use quick demos, if you need something more such as custom domains then you will need the paid account which starts at $5 per month.

Final Thoughts

Ngrok is one of those services that every developer should have in their toolbox. The dashboard is especially useful if you want to monitor the requests going to your service without another tool like fiddler. The free plan is good enough for most use cases, if you need more than the paid options are reasonable.

Originally published at on May 7, 2021.




Software Developer @

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alex Hyett

Alex Hyett

Software Developer @

More from Medium

Extend expiry date of SharePoint Online Client ID and Secret Key (Powershell)

.NET vs. Java: Which Platform Is Better For Software Development?

How to Build Mobile Applications on Microsoft Azure.

How to hide API keys from GitHub