Using Ngrok To Expose Your Localhost App

I was recently working on an application that was very API heavy and a few of these APIs needed to communicate with my app through webhooks. There are two very popular apps that can help us with this. Localtunnel and ngrok. Today, I’ll provide a quick guide on how to get up an running with ngrok.

First things first. Download the app from here. Once downloaded, create an account and run the following command from your terminal in a directory where the ngrok is located.

./ngrok authtoken YOURAUTHTOKEN

The auth token that’s needed will be listed on the ngrok account page once an account is created.

From there on just run the ngrok command from the terminal and this is what the config should look like.

To get the tunnel running. This is the command.

ngrok http 3000

Assuming your app is running on port 3000, otherwise you can replace the port portion with the necessary port. This is what it looks like when it’s up and running.

By default ngrok makes both http and https addresses available. With the free tier, ngrok will automatically assign a forwarding address for the app and that address will always be random. That can be a bit painful as the webhook address will need to be constantly changed to match the address ngrok assigns.

The $5 plan that ngrok offers allows the assignment of custom subdomains to overcome that hurdle. To assign a custom subdomain with a paid plan, the terminal command is as follows.

ngrok http -subdomanin=CUSTOMADDRESSHERE 3000

And that’s it. It really is as easy as this. Not only does this speed up webhook development, it actually allows other users to connect to the our app from the web for additional testing.

Software Engineer