node wrapper for ngrok


Ngrok exposes your localhost to the web.


It will download the ngrok 2.0 binary for your platform and put it into the bin folder. You can also install ngrok globally and use it directly from bash

$ npm install ngrok -g
$ ngrok http 8080

Attention, authtoken is required now because of tricky ngrok bug #27. Please go to ngrok 2.0 dashboard to obtain an authtoken. The one for ngrok 1.0 won't work. Many advanced features of the service require an authtoken, so it's a good thing anyway. As alternative, use module version 0.1.99 which uses ngrok 1.0 and doesn't require an authtoken.

You can pass it as option with each connect or set it once for further tunnels

ngrok.authtoken(token, function(errtoken) {});
var ngrok = require('ngrok');
ngrok.connect(function (errurl) {}); // -> http://localhost:80 
ngrok.connect(9090, function (errurl) {}); // -> http://localhost:9090 
ngrok.connect({proto: 'tcp', addr: 22}, function (errurl) {}); // tcp:// 
ngrok.connect(opts, function(errurl) {});

First connect spawns the ngrok process so each next tunnel is created much faster.

    proto: 'http', // http|tcp|tls 
    addr: 8080, // port or network address 
    auth: 'user:pwd', // http basic authentication for tunnel 
    subdomain: 'alex', // reserved tunnel name, 
    authtoken: '12345' // your authtoken from 
}, function (errurl) {});

Other options: name, inspect, host_header, bind_tls, hostname, crt, key, client_cas, remote_addr - read here

The ngrok and all tunnels will be killed when node process is done. To stop the tunnels use

ngrok.disconnect(url); // stops one 
ngrok.disconnect(); // stops all 
ngrok.kill(); // kills ngrok process 

Also you can use ngrok as an event emitter, it fires "connect", "disconnect" and "error" events

ngrok.once('connect', function (url) {};

You can use ngrok's configurations files, then just pass name option when making a tunnel

OS X    /Users/example/.ngrok2/ngrok.yml
Linux   /home/example/.ngrok2/ngrok.yml
Windows C:\Users\example\.ngrok2\ngrok.yml

When tunnel is established you can use the ngrok interface to inspect the webhooks done via ngrok.