Getting Started with Ngrok

Rajeeva Obeyesekera
Aeturnum
Published in
3 min readMar 7, 2018

--

“Ngrok” is a useful tool for anybody who is doing server side development. It streamlines the process of debugging server side code on your local machine and also helps to run your sever locally and have access to it from anywhere else. Let’s get started.

Sign up with Ngrok

Firstly, you need to create a free account in Ngrok. Go to the following url and create an account.

Install Ngrok

Once the account is created next step is to download and install Ngrok on the PC. Download the binary file depending on your operation sytems.

Note:This will download a Zip file. If you don’t have access to a GUI. Use the following command on Linux to unzip the folder.

# Install Unzip utilty if it's not previously installed on the machine.
sudo apt-get install unzip
# Include the zip file name and the destination folder where you need to copy the contents once the file is unzipped between <>unzip <download-zip-file.zip> -d <destination-folder>

Now we need to add the downloaded execuable to the “Path” environment variable. This make it easier to access it directly by the name.

Open up the terminal and navigate to the “Home” folder. Open the .bash_profile or .profile (If you’re on a Linux environment) and add the following line of code to the end of the file.

Rajeeva:~ rajeeva$ nano .bash_profileexport PATH="$PATH:"/<Path-to-Ngrok>/ngrok/""

Save the file and restart the terminal.

If the path has been configured correctly, following command yields the version of the ngrok utility that’s installed on the machine.

Rajeeva:~ rajeeva$ ngrok --versionngrok version 2.2.8

Configure Ngrok on the local machine

Now that Ngrok is installed flawlessly on the local machine. It should be configured to successfully authenticate with ngrok.com to properly function.

Go back to Ngrok dashboard and copy the access token from the “Auth” menu.

Then run the following command in the terminal.

Rajeeva:~ rajeeva$ ngrok authtoken <Paste the copied auth token here>
Authtoken saved to configuration file: /Users/rajeeva/.ngrok2/ngrok.yml

It’s done and dusted. Let’s start the server locally and have Ngrok do the rest.

Running Ngrok

Start your sever on the local host and expose the server port to Ngrok.

Note: You can use any server side framewrok to work with Ngrok. Only requirement here is to make sure that the local server is running successfully. Test the server by going to http://localhost:8080

Open up a new terminal session and enter the following command.

Rajeevas:~ rajeeva$ ngrok http <port>

This should open up a GUI on the terminal. This shows all the network statistics and publicly accessible urls for the local server instance.

Open your preferred web browser and load either urls that are displayed next to “Forwarding”. e.g: https://<some_udid>.ngrok.io/api/v1/login

That’s all. You now have a web sever which is accessible from anywhere in the world.

Conclusion

Ngrok is quite useful for many server side development work where it requires to quickly share your work with a client or a development team. It eliminates the need of doing rounds of server deployments which can be a hassle sometimes. It also handles TLS configurations by deafult which is a bonus to whoever finds it hard to manually configure SSL certificates in server instances.

Hope you find it useful. Happy coding.

--

--

Rajeeva Obeyesekera
Aeturnum

Software Engineer at Aeturnum. Fascinated by Artificial Inteligence. Former Electronic Engineering graduate at Sheffield Halam University, UK and SLIIT