ngrok vs localtunnel vs tunnel-rat
Web Development Tunneling Tools
ngroklocaltunneltunnel-rat

Web Development Tunneling Tools

Tunneling tools in web development allow developers to expose their local servers to the internet securely. These tools create a tunnel from a public URL to a local machine, enabling remote access for testing, collaboration, or showcasing projects without deploying them to a live server. They are particularly useful for webhooks, API testing, and sharing work-in-progress with clients or team members. localtunnel is a simple, open-source tool that provides quick and easy tunnels with minimal configuration. ngrok is a feature-rich platform offering secure tunnels, custom subdomains, and detailed analytics, making it ideal for professional use. tunnel-rat is a lightweight tunneling solution focused on simplicity and ease of use, suitable for quick sharing and testing.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
ngrok139,2592,41423.3 MB473 years agoBSD-2-Clause
localtunnel022,142-1664 years agoMIT
tunnel-rat044326.4 kB93 years agoMIT

Feature Comparison: ngrok vs localtunnel vs tunnel-rat

Ease of Setup

  • ngrok:

    ngrok requires a bit more setup, especially if you want to use advanced features like custom domains and authentication. However, it provides a user-friendly interface and comprehensive documentation.

  • localtunnel:

    localtunnel requires minimal setup and can be used directly from the command line. It is designed for quick and easy tunneling with no configuration needed.

  • tunnel-rat:

    tunnel-rat is designed to be simple and easy to set up, with minimal configuration required. It is ideal for users who want a hassle-free tunneling experience.

Security

  • ngrok:

    ngrok offers robust security features, including HTTPS tunnels, password protection, and IP whitelisting. It is a better choice for sensitive applications and professional use.

  • localtunnel:

    localtunnel provides basic security by generating random subdomains for each tunnel. However, it does not offer advanced security features like encryption or authentication.

  • tunnel-rat:

    tunnel-rat focuses on simplicity and does not provide advanced security features. It is suitable for non-sensitive applications and quick sharing.

Customization

  • ngrok:

    ngrok offers extensive customization options, including custom domains, subdomains, and the ability to configure tunnels programmatically. It is ideal for users who need more control over their tunneling setup.

  • localtunnel:

    localtunnel allows limited customization, such as specifying a subdomain if it is available. However, it is primarily designed for quick and simple use cases.

  • tunnel-rat:

    tunnel-rat offers basic customization features but is primarily focused on simplicity and ease of use. It is not designed for highly customizable tunneling solutions.

Analytics

  • ngrok:

    ngrok provides detailed analytics and monitoring, including request logs, traffic analysis, and performance metrics. This makes it a valuable tool for developers who need to track and analyze their tunnels.

  • localtunnel:

    localtunnel does not provide any analytics or monitoring features. It is a straightforward tunneling tool without any built-in tracking capabilities.

  • tunnel-rat:

    tunnel-rat does not include analytics or monitoring features. It is a lightweight tool focused on basic tunneling functionality.

Code Examples

  • ngrok:

    ngrok Example

    # Download and install ngrok from the official website
    
    # Expose your local server on port 3000
    ngrok http 3000
    
    # Optional: Use a custom subdomain (requires a paid plan)
    ngrok http -subdomain=yourname 3000
    
  • localtunnel:

    localtunnel Example

    # Install localtunnel globally
    npm install -g localtunnel
    
    # Expose your local server on port 3000
    tunnel --port 3000
    
  • tunnel-rat:

    tunnel-rat Example

    # Install tunnel-rat globally
    npm install -g tunnel-rat
    
    # Expose your local server on port 3000
    tunnel-rat 3000
    

How to Choose: ngrok vs localtunnel vs tunnel-rat

  • ngrok:

    Choose ngrok if you require a more robust solution with features like custom subdomains, password protection, and detailed analytics. It is suitable for professional use and scenarios where security and customization are important.

  • localtunnel:

    Choose localtunnel if you need a quick and easy way to expose your local server to the internet without any setup. It is ideal for simple use cases and quick demonstrations.

  • tunnel-rat:

    Choose tunnel-rat if you want a lightweight and straightforward tunneling tool that is easy to use and configure. It is great for quick sharing and testing without the need for advanced features.

README for ngrok

ngrok Tests TypeScript compatible npm npm

This project is the Node.js wrapper for the ngrok client. Version 5 of this project uses ngrok client version 3. For ngrok client version 2, check out version 4.

alt ngrok.com

Usage

Local install

Install the package with npm:

npm install ngrok

Then use ngrok.connect() to start ngrok and open a tunnel.

const ngrok = require('ngrok');
(async function() {
  const url = await ngrok.connect();
})();

This module uses node>=10.19.0 with async/await. For a callback-based version use 2.3.0.

Global install

npm install ngrok -g
ngrok http 8080

For global install on Linux, you might need to run sudo npm install --unsafe-perm -g ngrok due to the nature of npm postinstall script.

Auth Token

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

await ngrok.authtoken(token);

Or pass the authtoken to the connect method like so:

await ngrok.connect({authtoken: token, ...});

Connect

There are a number of ways to create a tunnel with ngrok using the connect method.

By default, connect will open an HTTP tunnel to port 80

const url = await ngrok.connect(); // https://757c1652.ngrok.io -> http://localhost:80

You can pass the port number to connect to specify that port:

const url = await ngrok.connect(9090); // https://757c1652.ngrok.io -> http://localhost:9090

Or you can pass an object of options, for example:

const url = await ngrok.connect({proto: 'tcp', addr: 22}); // tcp://0.tcp.ngrok.io:48590
const url = await ngrok.connect(opts);

Options

There are many options that you can pass to connect, here are some examples:

const url = await ngrok.connect({
  proto: 'http', // http|tcp|tls, defaults to http
  addr: 8080, // port or network address, defaults to 80
  basic_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, sa, jp, in), defaults to us
  configPath: '~/git/project/ngrok.yml', // custom path for ngrok config file
  binPath: path => path.replace('app.asar', 'app.asar.unpacked'), // custom binary path, eg for prod in electron
  onStatusChange: status => {}, // 'closed' - connection is lost, 'connected' - reconnected
  onLogEvent: data => {}, // returns stdout messages from ngrok process
});

See the ngrok documentation for all of the tunnel definition options including: name, inspect, host_header, scheme, hostname, crt, key, remote_addr.

Note on regions:

  • The region used in the first tunnel will be used for all the following tunnels
  • If you do not provide a region, ngrok will try to pick the closest one to your location. This will include the region in the URL. To get a URL without a region, set the region to "us".

Disconnect

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

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

Config

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

SystemPath
MacOS (Darwin)"~/Library/Application Support/ngrok/ngrok.yml"
Linux"~/.config/ngrok/ngrok.yml"
Windows"%HOMEPATH%\AppData\Local\ngrok\ngrok.yml"

You can specify a custom configPath when making a tunnel.

Updating config for ngrok version 3

With the upgrade to ngrok version 3, an older config file will no longer be compatible without a few changes. The ngrok agent provides a command to upgrade your config. On the command line you can run:

ngrok config upgrade

The default locations of the config file have changed too, you can upgrade and move your config file with the command:

ngrok config upgrade --relocate

The library makes this command available as well. To get the same effect you can run:

await ngrok.upgradeConfig();

// relocate the config file too:
await ngrok.upgradeConfig({ relocate: true });

Inspector

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

The same URL hosts the internal client api. This package exposes an API client that wraps the API which you can use to manage tunnels yourself.

const url = await ngrok.connect();
const api = ngrok.getApi();
const tunnels = await api.listTunnels();

You can also get the URL of the internal API:

const url = await ngrok.connect();
const apiUrl = ngrok.getUrl();

API

The API wrapper gives access to all the ngrok client API methods:

const url = await ngrok.connect();
const api = ngrok.getApi();

List tunnels

const tunnels = await api.listTunnels();

Start tunnel

const tunnel = await api.startTunnel(opts);

Get tunnel details

const tunnel = await api.tunnelDetail(tunnelName);

Stop tunnel

await api.stopTunnel(tunnelName);

List requests

await api.listRequests(options);

Replay request

await api.replayRequest(requestId, tunnelName);

Delete all requests

await api.deleteAllRequests();

Request detail

const request = await api.requestDetail(requestId);

Proxy

  • If you are behind a corporate proxy and have issues installing ngrok, you can set HTTPS_PROXY env var to fix it. ngrok's postinstall scripts uses the got module to fetch the binary and the hpagent module to support HTTPS proxies. You will need to install the hpagent module as a dependency
  • If you are using a CA file, set the path in the environment variable NGROK_ROOT_CA_PATH. The path is needed for downloading the ngrok binary in the postinstall script

How it works

npm install downloads the ngrok binary for your platform from the official ngrok hosting. To host binaries yourself set the NGROK_CDN_URL environment variable before installing ngrok. To force specific platform set NGROK_ARCH, eg NGROK_ARCH=freebsdia32.

The first time you create a tunnel the ngrok process is spawned and runs until you disconnect or when the parent process is killed. All further tunnels are connected or disconnected through the internal ngrok API which usually runs on http://127.0.0.1:4040.

ngrok binary update

If you would like to force an update of the ngrok binary directly from your software, you can require the ngrok/download module and call the downloadNgrok function directly:

const downloadNgrok = require('ngrok/download');
downloadNgrok(myCallbackFunc, { ignoreCache: true });

Using with nodemon

If you want your application to restart as you make changes to it, you may use nodemon. This blog post shows how to use nodemon and ngrok together so your server restarts but your tunnel doesn't.

Contributors

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

The test suite covers the basic usage without an authtoken, as well as features available for free and paid authtokens. You can supply your own tokens as environment variables, otherwise a warning is given and some specs are ignored (locally and in PR builds). GitHub Actions supplies real tokens to master branch and runs all specs always.

Upgrading to version 5

Please read the upgrade notes for the ngrok agent. Library specific changes are described below and there is more in the CHANGELOG:

Config

The format and default location of the config file has changed. Please see the section on upgrading your config file for more detail.

Connect options

The bind_tls option is now scheme. When bind_tls was true (the default), ngrok agent version 2 would start two tunnels, one on http and one on https. Now, when scheme is set to https (the default), only an https tunnel will be created. To create both tunnels, you will need to pass ["http", "https"] as the scheme option.

The auth option, also available as httpauth, is now just basic_auth. Note also that the password for basic_auth must be between 8 and 128 characters long.

Upgrading to version 4

The main impetus to update the package was to remove the dependency on the deprecated request module. request was replaced with got. Calls to the main ngrok functions, connect, authtoken, disconnect, kill, getVersion and getUrl respond the same as in version 3.

Updating the HTTP library, meant that the wrapped API would change, so a client class was created with methods for the available API calls. See the documentation above for how to use the API client.

The upside is that you no longer have to know the path to the API method you need. For example, to list the active tunnels in version 3 you would do:

const api = ngrok.getApi();
const tunnels = await api.get('api/tunnels');

Now you can call the listTunnels function:

const api = ngrok.getApi();
const tunnels = await api.listTunnels();

TypeScript

From version 3 to version 4 the bundled types were also overhauled. Most types live within the Ngrok namespace, particularly Ngrok.Options which replaces INgrokOptions.