How to demo your localhost app using ngrok
Tags: tutorials, ngrok, localhost, demo
Published: 2017-09-25 02:34:02

---
title: "How to demo your localhost app using ngrok"
published: true
tags: Tutorials, ngrok, localhost, demo
canonical_url: 
---

_Ngrok&nbsp;is a reverse proxy that allows you to expose your locally running web service to other developers. It’s a timesaver for developers when it comes down to showcasing a project. Follow along and learn how you can put this into your toolbelt of applications!_

Howdy everyone! Have you ever wanted to showcase an amazing project that you built at a hackathon; or show a client the progress of the app you’re building without deploying it to some server? A reverse proxy tool like&nbsp;[ngrok](https://ngrok.com/)&nbsp;can solve this. Let’s see how it works.

### The Sample App

We’ll need to start with a server running locally. If you don’t have a web app to test you can use a quick&nbsp;[Sinatra](http://sinatrarb.com)&nbsp;“Hello, World”:

```
# app.rb
require 'sinatra'

get '/' do
  'Hello World!'
end
```

We need to make sure to have the Sinatra gem. Install the gem through Terminal using:

```
$ gem install sinatra
```

To run our app, go into Terminal and write:

<!-- HTML generated using hilite.me -->

```
$ ruby app.rb
```

 ![](http://blog.clarifai.com/wp-content/uploads/2017/08/sinatra.gif)

And BOOOM!! 3-line Hello World app.

 ![](http://blog.clarifai.com/wp-content/uploads/2017/08/thats-wicked.gif)


### Ngrok

Ngrok is a tool made by [Alan Shreve](https://twitter.com/inconshreveable),&nbsp;who built it to be as accessible as possible by breaking it down into 3 painless steps:

1. [Download ngrok for your OS](https://ngrok.com/download)
2. Unzip it
3. Launch it!

Ta-dah! You’re a natural!

Here we will launch ngrok through both macOS/Linux and Windows. Let’s move the executable from my Downloads to our Home folder (marked as the tilde or ~) for our macOS/Linux friends. Open up a new terminal and write:

```
$ mv /your/path/to/ngrok ~
```

For Windows we are moving the ngrok.exe to my particular User directory. Mine is called Administrator but yours could be your name (i.e. “Prince Wilson”).

```
$ move \your\path\to\ngrok \Users\<PC_Name>
```

We are going to execute ngrok straight from our current directory. In macOS you prepend a script with a â€˜./’ to make it execute and in Windows you would use â€˜.\’. Otherwise your Terminal will look for ngrok in your PATH. ngrok requires at least two fields: 1) the protocol (i.e. HTTP) and 2) the port we want to expose. If you are running your own app pop in the port it’s using otherwise Sinatra defaults to port 4567.

```
$ ./ngrok http 4567
```

 ![](http://blog.clarifai.com/wp-content/uploads/2017/08/ngrok.gif)

```
$ .\ngrok http 4567
```

 ![](http://blog.clarifai.com/wp-content/uploads/2017/08/ngrok_windows.gif)

It fires up with a bunch of outputs but we only care about the forwarding url right now. Mine is &nbsp;“[http://da0dcb04.ngrok.io](http://da0dcb04.ngrok.io)” or “[http://f4fcf6f0.ngrok.io](http://f4fcf6f0.ngrok.io)”. Notice that it points to where our sample server is, meaning anyone who hits our link will be forwarded to our sample app!

 ![](http://blog.clarifai.com/wp-content/uploads/2017/08/hello_world.gif)

### Conclusion

And with that, you have learned the basics of ngrok. But, there is so much more to learn! Try these to improve your experience:

- To inspect the traffic coming through and replay requests check out [http://localhost:4040](http://localhost:4040). Learn more about that in the [ngrok documentation](https://ngrok.com/docs#inspect).
- Sign up for an ngrok account if you want to use your own Basic Authentication. What’s there to lose?
- There are a ton of neato burrito things you can also get out of supporting the project so &nbsp;pony up if you have the funds to help the software grow.

If you have any questions or want to share your experience with ngrok feel free to send me a note over at [hackers@clarifai.com](mailto:hackers@clarifai.com); I’d love to hear from you!