Using ngrok to test local websites and APIs

Using ngrok to test local websites and APIs

by | 2 min read

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.

Chances are however 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 then 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.

🚀 Are you looking to level up your engineering career?

You might like my free weekly newsletter, The Curious Engineer, where I give career advice and tackle complex engineering topics.

📨 Don't miss out on this week's issue
  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 Window

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.

ngrok on iPhone

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

ngrok dashboard

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.

🙏 Was this helpful? If you want to say thanks, I love coffee ☕️ , any support is appreciated.


How to do Performance Testing with k6

How to do Performance Testing with k6

  • 06 October 2023
If you haven’t done any performance testing before, then k6 is a really simple free tool that you can use to do it. Now you might be…
Types of Software Testing Explained

Types of Software Testing Explained

  • 03 March 2023
We all know how important it is to test our code but there are so many different types of tests that it can be difficult to work out which…
Software Testing Methodologies - Guide

Software Testing Methodologies - Guide

  • 13 February 2023
Software development often gets a bad reputation for being costly and time-consuming. This is often due to bad planning and estimation…
Unit Testing vs Integration Testing - Key Differences

Unit Testing vs Integration Testing - Key Differences

  • 03 February 2023
Testing is an important part of a developer’s toolkit. After all, how are you supposed to know whether your software is doing what it was…
Using for Integration Testing

Using for Integration Testing

  • 22 May 2021
Last week I showed you how you can use Wiremock in a docker container to mock API calls that your application uses. This week is on a…
Mocking API calls using WireMock

Mocking API calls using WireMock

  • 14 May 2021
It is rare in software development that you are building something in complete isolation from everything else. Generally, you are going to…