May 19, 2020

Using ngrok to Expose a Local Server

Sometimes we want to test how our application looks and functions on a separate device. Using ngrok can help us expose a local server and access it online.

ngrok is a utility that can expose a web server running on your local machine to a configured URL that can be access online.

Exposing a local server via a publicly-accessible URL can be very useful for developers and QAs because you can demo your sites without requiring a deploy.

ngrok Homepage

Installing ngrok on Mac OSX

Using brew is the best way to install ngrok on your machine:

brew cask install ngrok

There are two alternative options:

  • One popular option is to use NPM:
npm install -g ngrok
  • Ngrok provides an official installer but you will need to sign up for the service before obtaining the download link.

You don't need to sign up to use ngrok but it does offer more privileges. More on this in the last section.

Exposing a Local Server

If your local project is already running on a specific port (such as 8000), you can just run:

ngrok http 8000

This will generate a publicly-accessible URL with HTTPS support. You can then use it to open the URL on a seperate device.

Authenticating with ngrok (Optional)

This is optional but doing so allows you to have longer session times and a maintainable list of running tunnels that you can see in the dashboard.

  1. Sign up for ngrok (free)
  2. Look for your authtoken in the Setup & Installation section.
  3. Run the following command in the terminal with your authorization token:
ngrok authtoken YOUR-TOKEN

This will add your authorization token to the ngrok.yml configuration file so that it is saved locally.

  1. Fire up an ngrok server
ngrok http 8000

You can now check that the generated URL is also listed in the Tunnels section:

That is all it takes to create a publicly-accessible URL that we can use to demo our site and test our features. I hope you find the tutorial useful. As always, thanks for dropping by.

development port tunneling

Last updated: May 20, 2020