UNPKG

4.34 kBMarkdownView Raw
1# localtunnel
2
3localtunnel exposes your localhost to the world for easy testing and sharing! No need to mess with DNS or deploy just to have others test out your changes.
4
5Great for working with browser testing tools like browserling or external api callback services like twilio which require a public url for callbacks.
6
7## Quickstart
8
9```
10npx localtunnel --port 8000
11```
12
13## Installation
14
15### Globally
16
17```
18npm install -g localtunnel
19```
20
21### As a dependency in your project
22
23```
24yarn add localtunnel
25```
26
27## CLI usage
28
29When localtunnel is installed globally, just use the `lt` command to start the tunnel.
30
31```
32lt --port 8000
33```
34
35Thats it! It will connect to the tunnel server, setup the tunnel, and tell you what url to use for your testing. This url will remain active for the duration of your session; so feel free to share it with others for happy fun time!
36
37You can restart your local server all you want, `lt` is smart enough to detect this and reconnect once it is back.
38
39### Arguments
40
41Below are some common arguments. See `lt --help` for additional arguments
42
43- `--subdomain` request a named subdomain on the localtunnel server (default is random characters)
44- `--local-host` proxy to a hostname other than localhost
45
46You may also specify arguments via env variables. E.x.
47
48```
49PORT=3000 lt
50```
51
52## API
53
54The localtunnel client is also usable through an API (for test integration, automation, etc)
55
56### localtunnel(port [,options][,callback])
57
58Creates a new localtunnel to the specified local `port`. Will return a Promise that resolves once you have been assigned a public localtunnel url. `options` can be used to request a specific `subdomain`. A `callback` function can be passed, in which case it won't return a Promise. This exists for backwards compatibility with the old Node-style callback API. You may also pass a single options object with `port` as a property.
59
60```js
61const localtunnel = require('localtunnel');
62
63(async () => {
64 const tunnel = await localtunnel({ port: 3000 });
65
66 // the assigned public url for your tunnel
67 // i.e. https://abcdefgjhij.localtunnel.me
68 tunnel.url;
69
70 tunnel.on('close', () => {
71 // tunnels are closed
72 });
73})();
74```
75
76#### options
77
78- `port` (number) [required] The local port number to expose through localtunnel.
79- `subdomain` (string) Request a specific subdomain on the proxy server. **Note** You may not actually receive this name depending on availability.
80- `host` (string) URL for the upstream proxy server. Defaults to `https://localtunnel.me`.
81- `local_host` (string) Proxy to this hostname instead of `localhost`. This will also cause the `Host` header to be re-written to this value in proxied requests.
82- `local_https` (boolean) Enable tunneling to local HTTPS server.
83- `local_cert` (string) Path to certificate PEM file for local HTTPS server.
84- `local_key` (string) Path to certificate key file for local HTTPS server.
85- `local_ca` (string) Path to certificate authority file for self-signed certificates.
86- `allow_invalid_cert` (boolean) Disable certificate checks for your local HTTPS server (ignore cert/key/ca options).
87
88Refer to [tls.createSecureContext](https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options) for details on the certificate options.
89
90### Tunnel
91
92The `tunnel` instance returned to your callback emits the following events
93
94| event | args | description |
95| ------- | ---- | ------------------------------------------------------------------------------------ |
96| request | info | fires when a request is processed by the tunnel, contains _method_ and _path_ fields |
97| error | err | fires when an error happens on the tunnel |
98| close | | fires when the tunnel has closed |
99
100The `tunnel` instance has the following methods
101
102| method | args | description |
103| ------ | ---- | ---------------- |
104| close | | close the tunnel |
105
106## other clients
107
108Clients in other languages
109
110_go_ [gotunnelme](https://github.com/NoahShen/gotunnelme)
111
112_go_ [go-localtunnel](https://github.com/localtunnel/go-localtunnel)
113
114## server
115
116See [localtunnel/server](//github.com/localtunnel/server) for details on the server that powers localtunnel.
117
118## License
119
120MIT