Using ngrok to test local websites and APIs

By Alex Hyett on in Software Development

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 mimicing 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 ngrok.com 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 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 their 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 of 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.


Was this post useful?
If you found this post useful and would like to support me, you can do so by buying me a coffee. Donations help keep this blog ad-free.

ALSO ON ALEXHYETT.COM

Dealing with Imposter Syndrome as a Software Developer

Dealing with Imposter Syndrome as a Software Developer

  • 28 May 2021
I have been a professional software developer for over a decade and I have been writing code for over 25 years. However, sometimes I still…
Using WireMock.net for Integration Testing

Using WireMock.net for Integration Testing

  • 21 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…
Using GitHub Actions to Deploy to S3

Using GitHub Actions to Deploy to S3

  • 26 March 2021
Recently I went through the process of setting up Drone CI on my Raspberry Pi. The plan was to use my Raspberry Pi as a build server for…
Getting Started with AWS Step Functions

Getting Started with AWS Step Functions

  • 12 March 2021
I have recently been looking into AWS Step Functions. For those not familiar with them, Step Functions are Amazon’s way of providing a state…
Useful Docker Commands Worth Saving

Useful Docker Commands Worth Saving

  • 12 February 2021
I use docker every day. All the applications I write at work or at home end up in docker containers. Most of the time though, I am only…
Grafana Monitoring on a Raspberry Pi

Grafana Monitoring on a Raspberry Pi

  • 28 January 2021
As you might have seen from my last few posts I have quite a lot running on my Raspberry Pi. I am currently using a Raspberry Pi 2 B which…

Alex Hyett
WRITTEN BY

Alex Hyett

Software Developer, Entrepreneur, Father, and Husband. Engineering Lead at Checkout.com.

Want to get in touch? You can find me here:


Join the Newsletter

Subscribe to get my latest content by email.

    I won't send you spam. Unsubscribe at any time.