Giter VIP home page Giter VIP logo

ngrok's Introduction

ngrok Build Status TypeScript compatible npm npm

alt ngrok.com

usage

npm install ngrok
var ngrok = require('ngrok');
ngrok.connect(function (err, url) {});

or

npm install ngrok -g
ngrok http 8080

authtoken

You can create basic http-https-tcp tunnel without authtoken. For custom subdomains and more you should obtain authtoken by signing up at ngrok.com. Once you set it, it's stored in ngrok config and used for all tunnels. Few ways:

ngrok.authtoken(token, function(err, token) {});
ngrok.connect({authtoken: token, ...}, function (err, url) {});
ngrok authtoken <token>

connect

var ngrok = require('ngrok');

ngrok.connect(function (err, url) {}); // https://757c1652.ngrok.io -> http://localhost:80
ngrok.connect(9090, function (err, url) {}); // https://757c1652.ngrok.io -> http://localhost:9090
ngrok.connect({proto: 'tcp', addr: 22}, function (err, url) {}); // tcp://0.tcp.ngrok.io:48590
ngrok.connect(opts, function(err, url) {});

options

ngrok.connect({
	proto: 'http', // http|tcp|tls
	addr: 8080, // port or network address
	auth: 'user:pwd', // http basic authentication for tunnel
	subdomain: 'alex', // reserved tunnel name https://alex.ngrok.io
	authtoken: '12345', // your authtoken from ngrok.com
	region: 'us' // one of ngrok regions (us, eu, au, ap), defaults to us,
	configPath: '~/git/project/ngrok.yml' // custom path for ngrok config file
}, function (err, url) {});

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

Note on regions: region used in first tunnel will be used for all next tunnels too.

disconnect

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

Note on http tunnels: by default bind_tls is true, so whenever you use http proto two tunnels are created - http and https. If you disconnect https tunnel, http tunnel remains open. You might want to close them both by passing http-version url, or simply by disconnecting all in one go ngrok.disconnect().

emitter

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

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

configs

You can use ngrok's configurations files, and just pass name option when making a tunnel. Configuration files allow to store tunnel options. Ngrok looks for them here:

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

You can specify a custom configPath when making a tunnel.

inspector

When tunnel is established you can use the ngrok interface http://127.0.0.1:4040 to inspect the webhooks done via ngrok.

how it works

npm install downloads ngrok binaries for you platform and puts them into bin folder. You can host binaries yourself and set NGROK_CDN_URL env var before installing ngrok. Or you can force specific arch by setting NGROK_ARCH, eg NGROK_ARCH=freebsdia32

First time you create tunnel ngrok process is spawned and runs until you disconnect or when parent process killed. All further tunnels are created or stopped by using internal ngrok api which usually runs on http://127.0.0.1:4040

contributors

Please run git update-index --assume-unchanged bin/ngrok to not override ngrok stub in your pr. Unfortunately it can't be gitignored.

ngrok's People

Contributors

bubenshchykov avatar lightsofapollo avatar eagleeye avatar javagarcia avatar nkzawa avatar cesarandreu avatar dfiloni avatar esrefdurna avatar hem-brahmbhatt avatar jcblw avatar jfromaniello avatar jnovack avatar p-j avatar keithws avatar marcbachmann avatar marszall87 avatar toverux avatar atgardner avatar mastilver avatar gaoqiankun avatar jessefulton avatar mmkal avatar

Watchers

Chua Kiem Fai avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.