Have you ever come across an obstacle while programming and then immediately come across a solution so elegant that you don’t know how you were surviving without knowing about it before?
I have, and the solution was called Ngrok.
Testing locally with certain APIs can be a real hassle at times – and if you’re in a position where pushing unstable code to your staging server isn’t doable, it can really cause problems. I was dreading having to test my Twilio webhooks until I came across Ngrok, an extremely nifty little program that you can use to temporarily expose your local server to the Internet.
I literally had Ngrok downloaded, installed and running on my machine in less than 5 minutes. You download a zip file, unzip it into whatever folder you want, navigate to that folder and run this command (where “3000” represents the port that you want to expose):
./ngrok http 3000
it achieves this by setting up tunnel urls – urls that the API can access but get re-routed to your local machine. Running this command will generate and give you access to your tunnel URLs, which you can use for whatever you need. I used them to plug into my Twilio admin panel to test my webhooks – and it was extremely easy! But there are lots of scenarios where this could be useful. Ever wanted to let your colleagues run tests on your local configuration? Ever wanted to run a demo for a client without going through the hassle of deployment? All of this can be facilitated using Ngrok.
But wait – there’s more! Once you have Ngrok running, try going to localhost:4040. That’s right, now you can see the logs for all the traffic that’s passing through your tunnel URLs.
Honestly, it couldn’t be any easier. It’s a great feeling when you come across a tool that you immediately know is going to change your workflow forever and Ngrok is already essential to mine.