Socket
Socket
Sign inDemoInstall

ngrok2

Package Overview
Dependencies
68
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    ngrok2

Node.js wrapper for ngrok v2.x


Version published
Weekly downloads
0
Maintainers
1
Created
Weekly downloads
 

Readme

Source

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

Keywords

FAQs

Last updated on 11 Aug 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc