localtunnel-plus
v2.1.1
Published
Expose localhost to the world
Readme
localtunnel
Version 2.1.1 - Now with WORKING keep-alive mode!
localtunnel 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.
Great for working with browser testing tools like browserling or external api callback services like twilio which require a public url for callbacks.
⚡ What's New
v2.1.1 (Latest) - Critical Keep-Alive Fixes
- 🐛 FIXED: Keep-alive now actually works (pipes with
{ end: false }) - 🐛 FIXED: Deprecated url.parse() warning removed
- ✅ Unlimited requests with
--keep-aliveflag - ✅ Testing guide added (
TESTING_KEEPALIVE.md)
v2.1.0 - Major Security & Features
- ✅ Security: Updated all dependencies, fixed critical axios vulnerability
- ✅ Documentation: Comprehensive JSDoc, security analysis, and troubleshooting guides
- ✅ Persistent Connections: Experimental
--keep-alivemode to prevent socket exhaustion - ✅ Better Errors: Improved error messages and debugging output
- ✅ TCP Keep-Alive: Automatic detection of broken connections
⚠️ Important Notes
Socket Exhaustion Issue
The standard client closes tunnel sockets after each request, which can cause the tunnel to become unavailable after N requests (where N = max_conn_count from server).
Solutions:
- ✅ Use
--keep-aliveflag (now working in v2.1.1!) - Increase server's
--max-socketssetting - Implement auto-restart (see
SOCKET_BEHAVIOR.md)
For details, see SOCKET_BEHAVIOR.md and TESTING_KEEPALIVE.md
Security
Always implement authentication on your local service. LocalTunnel creates a public URL accessible from anywhere!
For security best practices, see SECURITY_ANALYSIS.md
Quickstart
npx localtunnel --port 8000Installation
Globally
npm install -g localtunnelAs a dependency in your project
yarn add localtunnelHomebrew
brew install localtunnelCLI usage
When localtunnel is installed globally, just use the lt command to start the tunnel.
lt --port 8000Thats 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!
You can restart your local server all you want, lt is smart enough to detect this and reconnect once it is back.
Arguments
Below are some common arguments. See lt --help for all options.
Basic Options
--portor-p(required) - Internal HTTP server port--hostor-h- Upstream server providing forwarding (default:https://localtunnel.me)--subdomainor-s- Request a named subdomain on the localtunnel server (default is random)--local-hostor-l- Proxy to this hostname instead of localhost--openor-o- Opens the tunnel URL in your browser--print-requests- Print basic request info to console
HTTPS Options
--local-https- Tunnel traffic to a local HTTPS server--local-cert- Path to certificate PEM file for local HTTPS server--local-key- Path to certificate key file for local HTTPS server--local-ca- Path to certificate authority file for self-signed certificates--allow-invalid-cert- Disable certificate checks (use only in development!)
⚡ New Options (v2.1.0)
--keep-alive- Experimental: Keep tunnel connections alive for reuse
Environment Variables
You may also specify arguments via env variables:
PORT=3000 lt
HOST=https://tunnel.example.com ltExamples
# Basic usage
lt --port 3000
# Custom subdomain
lt --port 8080 --subdomain my-app
# Custom tunnel server
lt --port 3000 --host https://tunnel.yourdomain.com
# Local HTTPS server
lt --port 443 --local-https --local-cert ./cert.pem --local-key ./key.pem
# With monitoring
lt --port 3000 --print-requests
# Experimental persistent connections
lt --port 3000 --keep-alive
# Open in browser
lt --port 3000 --openAPI
The localtunnel client is also usable through an API (for test integration, automation, etc)
localtunnel(port [,options][,callback])
Creates 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.
const localtunnel = require("localtunnel");
(async () => {
const tunnel = await localtunnel({ port: 3000 });
// the assigned public url for your tunnel
// i.e. https://abcdefgjhij.localtunnel.me
tunnel.url;
tunnel.on("close", () => {
// tunnels are closed
});
})();options
Basic Options
port(number) [required] The local port number to expose through localtunnel.subdomain(string) Request a specific subdomain on the proxy server. Note: You may not actually receive this name depending on availability.host(string) URL for the upstream proxy server. Defaults tohttps://localtunnel.me.local_host(string) Proxy to this hostname instead oflocalhost. This will also cause theHostheader to be re-written to this value in proxied requests.
HTTPS Options
local_https(boolean) Enable tunneling to local HTTPS server.local_cert(string) Path to certificate PEM file for local HTTPS server.local_key(string) Path to certificate key file for local HTTPS server.local_ca(string) Path to certificate authority file for self-signed certificates.allow_invalid_cert(boolean) Disable certificate checks for your local HTTPS server (ignore cert/key/ca options).
Refer to tls.createSecureContext for details on the certificate options.
⚡ Advanced Options (v2.1.1)
keep_alive(boolean) Keep tunnel connections alive for reuse. Prevents socket exhaustion. Defaults tofalse.
Example with keep_alive:
const localtunnel = require("localtunnel");
(async () => {
const tunnel = await localtunnel({
port: 3000,
keep_alive: true // Enable persistent connections
});
console.log('Tunnel URL:', tunnel.url);
tunnel.on("request", req => {
console.log('Request:', req.method, req.path);
});
})();Tunnel
The tunnel instance returned to your callback emits the following events
| event | args | description | | ------- | ---- | ------------------------------------------------------------------------------------ | | request | info | fires when a request is processed by the tunnel, contains method and path fields | | error | err | fires when an error happens on the tunnel | | close | | fires when the tunnel has closed |
The tunnel instance has the following methods
| method | args | description | | ------ | ---- | ---------------- | | close | | close the tunnel |
other clients
Clients in other languages
go gotunnelme
C#/.NET localtunnel-client
Rust rlt
📚 Documentation
- TESTING_KEEPALIVE.md - ⚡ NEW! Test guide for keep-alive mode
- SOCKET_BEHAVIOR.md - Understanding socket exhaustion and solutions
- SECURITY_ANALYSIS.md - Security best practices and vulnerability fixes
- CHANGELOG.md - Version history and changes
🔧 Troubleshooting
Tunnel Becomes Unavailable After N Requests
Problem: After a certain number of requests, you get "connection refused" errors.
Cause: Socket exhaustion (see SOCKET_BEHAVIOR.md)
Quick Fixes:
# Option 1: Use keep-alive (WORKING in v2.1.1!)
lt --port 3000 --keep-alive
# Option 2: Auto-restart with systemd or supervisorTest keep-alive: See TESTING_KEEPALIVE.md for complete testing guide.
Connection Refused Errors
Problem: Error: connection refused: IP:PORT
Solutions:
- Check your firewall settings
- Verify the tunnel server is running
- Try a different
--hostoption
HTTPS Certificate Errors
Problem: Certificate validation failures
Solutions:
# Development only - allow self-signed certs
lt --port 3000 --local-https --allow-invalid-cert
# Production - use valid certificates
lt --port 3000 --local-https --local-cert ./cert.pem --local-key ./key.pem🚀 Production Deployment
For production use:
- Use a custom tunnel server (not public localtunnel.me)
- Implement authentication on your local service
- Enable auto-restart (systemd, PM2, etc.)
- Monitor requests with
--print-requests - Use HTTPS for sensitive data
Example systemd service:
[Unit]
Description=LocalTunnel Client
After=network.target
[Service]
Type=simple
User=myuser
ExecStart=/usr/bin/lt --port 3000 --host https://tunnel.example.com --keep-alive
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.targetserver
See localtunnel/server for details on the server that powers localtunnel.
For our improved server with persistent connections support, contact the maintainers.
other clients
Clients in other languages
go gotunnelme
C#/.NET localtunnel-client
Rust rlt
🤝 Contributing
Contributions welcome! Please:
- Read the documentation
- Test your changes
- Update docs if needed
- Submit a pull request
📄 License
MIT
