Developing enterprise software and websites within a local environment can be somewhat cumbersome at times; especially to test features and style changes within a mobile environment. Just when we think that we have perfected this shinny new addition, quality assurance or the client may shed some light on a bug that can only be found on an iPhone. The common question usually arises: how do I test my code on my phone without having to submit a pull request for the remote development environment?

The problem and solution

Using something like Yeoman's web application generator will provide you with public facing url's while you develop; which is nice. However not EVERY platform provides you with these features out of the box. Usually the "go fend for yourself" method is the way of the road. That is the case for most enterprise systems, regardless of the language, and even smaller scale virtual environments like MAMP.

The answer in this instance is a NodeJS module labeled LocalTunnel. LocalTunnel allows you to publicly broadcast your localhost port with a public facing URL that can be accessed from a phone or any other device.

How to use LocalTunnel

1. Open up the terminal/command line interface on your machine and enter the following command:

npm install -g localtunnel  

NOTE: This does require NodeJS to be installed on your computer.

2. Once complete, you now have the lt library of commands available to you. You can see all of the available commands and parameters simply by typing lt into your terminal.

LocalTunnel sample screenshot

3. Depending on the type of virtual environment that you are using, the port number will vary. MAMP defaults to port 8888 so that is what we will use for the sake of this demo. With that said, we need to tell LocalTunnel to look at port 8888. So to start up LocalTunnel, enter the following command into your terminal:

lt --port 8888  

Assuming that everything was configured correctly, you should see a response telling you where your localhost can be located (for example: https://wjvtotihbx.localtunnel.me).

4. Once your are finished, simply close the terminal window or use the Ctrl + C key combination to cancel the process.

‚ÄčThat's it! Hope this helps.