0.2.7 • Published 9 years ago

ngrok2 v0.2.7

Weekly downloads
5
License
MIT
Repository
github
Last release
9 years ago

Nodejs wrapper for ngrok v 2.x

Project is under construction

##Description ngrok package contains two main classes : NgrokCLI - command line wrapper and NgrokAPI - HTTP API wrapper. ngrok function returns Promise, which returns object with wrappers for both APIs :

{
   api : 'instance of NgrokAPI,'
   cli : 'instance of NgrokCLI' //extends EventEmiter
}

but also it contains NgrokAPI and NgrokCLI constructors (see below how to get them)

###NgrokCLI events :

  • webserver - emit when ngrok start web server on some port
  • can-handle - emit when ngrok able to handle requests to API
  • cli-entry - emit when ngrok log JSON-like data to CLI
  • cli-line - emit when ngrok log plain text to CLI
  • all-stopped - emit when ngrok completely stopped, not reliable, sometimes close emit before this event
  • close, error, exit - as usual for child process

NgrokCLI constructor accepts two optional arguments : authtoken and configPath default is $HOME/.node-ngrok.yml. It's instance has only two public methods :

  • start({Object} config, {Function} callback) -> return Promise
  • stop({Function} callback) -> return Promise

###NgrokAPI methods:

  • getTunnels({Function}callback),
  • getTunnel({String} name, {Function}callback),
  • addTunnel({object} param, {Function}callback),
  • stopTunnel({String} name, {Function}callback)

NgrokAPI constructor accepts one required argument : address like http://127.0.0.1:4040

getTunnel and stopTunnel add small delay (100ms) to "queue", therefore getTunnel and getTunnels will wait for a while. This behavior is caused by the fact that ngrok can't return updated tunnels list immediatly.

##Usage:

var ngrok = require('ngrok2');
ngrok(config).then(function (ng) {
    ng.api.addTunnel({proto: 'tcp', addr: '22', name: 'ssh'}).then(function (tunnel) {
        debug('tunnel added', tunnel);
        ng.api.getTunnels().then(function (tunnels) {
            debug('these tunnels now exists', tunnels);
            ng.api.stopTunnel('ssh').then(function (tunnels) {
                debug('these tunnels still work', tunnels);
            });
        });
    });
});
//or:
var NgrokCLI = ngrok.NgrokCLI;
var NgrokAPI = ngrok.NgrokAPI;
//do all your magic with these classes directly

###Config example

{
  "authtoken": "YOUR_TOKEN",
  "compress_conn": false,
  "http_proxy": false,
  "inspect_db_size": 50000000,
  "metadata": "",
  "root_cas": "trusted",
  "socks5_proxy": "",
  "update": true,
  "update_channel": "stable",
  "web_addr": "127.0.0.1:4040"
}

For more information go here

Run with debug:

DEBUG=cli-log,cli-event,api,index node myAwesomeScript.js
#or
DEBUG=* node myAwesomeScript.js

License: MIT License

0.2.7

9 years ago

0.2.6

9 years ago

0.2.5

9 years ago

0.2.4

9 years ago

0.2.2

9 years ago

0.2.1

9 years ago