Ngrok is a tunneling tool used to expose applications running locally to the public over the internet. Ngrok sits between the public and your local application by proxying external requests to the port your application is running on. Ngrok comes in quite handy when you need a publicly accessible URL.
If you have been following the guides from this blog, you might have noticed that most webhook providers expect you to provide an HTTPS secured URL while registering a webhook. While this practice among webhook providers is put in place to ensure security, it becomes difficult to work with webhooks in a development environment — Where your local server is yet to have an HTTPS secured URL. Ngrok makes it possible to get a publicly available HTTPS URL that maps to your local server.
In this guide, we will learn how to set up Ngrok to receive publicly accessible URLs for applications running locally.
To be able to use Ngrok on your computer, you first have to install it on your machine!
To install Ngrok:
- Head over to the official website and download the release suitable for your local machine.
- Once downloaded, unzip the file and follow the prompts to install Ngrok to your machine. If you get stuck while installing Ngrok, the official download page has some pretty clear documentation that I definitely recommend you check out.
Asides from manually downloading Ngrok from the official site, you can install Ngrok on your computer using NPM if you have NPM configured.
To install Ngrok using NPM:
- Run the following command
npm i ngrok
- After running this command, NPM will download the Ngrok binary from the official Ngrok hosting.
To learn more about the NPM method of installing Ngrok, head over to the official NPM page.
Once Ngrok has been installed on the computer, you can go ahead and run your tunnel. Running Ngrok is quite easy: the command to run Ngrok follows this pattern
— ngrok http <port-number>
Ngrok will start in your terminal, displaying a box that contains your forwarding field. Ngrok will tunnel any external traffic to your application running on of your machine. The forwarding field's value displayed in the terminal is the most important piece in this puzzle. The forwarding URL receives incoming traffic and maps it to your local application. You can now use the HTTPS secure URL for working with webhooks in a development environment!
So far, we have learned about Ngrok & how to set it up. While everything is set up to work perfectly for development, we recommend talking to the necessary authorities before starting Ngrok over a public network. It could expose the network to vulnerabilities.
Interested to learn more? Follow Hookdeck where I'll be sharing tutorials and guide about webhooks!
Try Hookdeck For Free. Receive, monitor and manage all your webhooks from a single place. We handle the complexity so you can focus on building your product.