Skip to content

Guide · Open source

How to use localtunnel: expose localhost with one command

Updated · written with AI from the project's own documentation and checked against our catalogue data

localtunnel exposes a service running on your own computer (localhost) through a temporary public web address. This guide shows you how to start a tunnel from the command line, pick a subdomain, and call it from JavaScript. You will also see what localtunnel is not designed for.

localtunnellocaltunnel/localtunnel · ★ 22.5k · MIT

Quick start

  1. 1Start your local server. Run the web app or service you want to share on a local port, such as 8000.
  2. 2Open a tunnel. Run npx localtunnel --port 8000 or, after a global install, lt --port 8000.
  3. 3Copy the public URL. Use the address localtunnel prints as the public URL for your testing or sharing.
  4. 4Set a subdomain if needed. Add --subdomain with a name you want. The server may assign a different one if the name is unavailable.
  5. 5Automate it if needed. Use the JavaScript API to open a tunnel from a test script and read tunnel.url.
  6. 6Close when finished. Stop the process or call tunnel.close() so the tunnel shuts down.

Start a tunnel with npx (no install)

If you want to try localtunnel without installing anything, run it with npx. Replace 8000 with the port your local server is listening on.

localtunnel then connects to the tunnel server, sets up the tunnel, and tells you which URL to use for testing.

npx localtunnel --port 8000

Install localtunnel globally or in a project

To use the short lt command everywhere, install localtunnel globally with npm. To use it as a dependency in a project, add it with yarn. The README also lists Homebrew as an install option.

Node.js is required. The README does not specify which Node.js version you need.

  • Global install with npm
  • Project dependency with yarn
  • Homebrew: brew install localtunnel
npm install -g localtunnel

Use the lt command to open a tunnel

When localtunnel is installed globally, run lt with the port of your local server. The public URL stays active for the duration of your session, so you can share it with others.

You can restart your local server without restarting the tunnel. According to the README, lt detects the restart and reconnects once the server is back.

lt --port 8000

Set common options like subdomain and local host

The README lists a few common arguments. Run lt --help to see the rest.

--subdomain asks for a named subdomain; the default is random characters. Note that the server may not grant the name you request. --local-host proxies to a hostname other than localhost.

You can also set the port with an environment variable.

  • --subdomain: request a named subdomain (default is random characters)
  • --local-host: proxy to a hostname other than localhost
PORT=3000 lt

Open a tunnel from JavaScript

The client also works as an API for test integration and automation. Calling localtunnel with a port returns a Promise that resolves to a tunnel object with a url property. You can also pass a single options object with port as a property.

The tunnel emits request, error and close events. You can close it with tunnel.close(). The options include subdomain, host (default https://localtunnel.me), local_host, and several local HTTPS settings such as local_https, local_cert, local_key, local_ca and allow_invalid_cert.

  • request: fires when a request is processed, with method and path fields
  • error: fires when an error happens on the tunnel
  • close: fires when the tunnel has closed
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 }); })();

Know the limits before you rely on it

localtunnel is built for testing and sharing. The tunnel exists only while your session runs, so it is not a production host. The README also does not describe access restrictions or privacy controls, so do not assume your local app is protected while it is exposed.

Client libraries exist for Go, C#/.NET and Rust, and the server that powers localtunnel is a separate project (localtunnel/server).

What people use it for

  • Show a local web app to a colleague for a quick review
  • Receive callbacks from a service such as Twilio that needs a public URL
  • Give a browser testing tool a reachable address for your local site
  • Open a temporary tunnel from an automated test script with the JavaScript API

Frequently asked questions

Is localtunnel free?

localtunnel is released under the MIT licence, which the README states. The README does not describe pricing or hosted plans, so check the project's homepage for current details.

Do I need to install anything to try localtunnel?

No. The README's quickstart runs npx localtunnel --port 8000, which uses npx to run the tool without a global install. You do need Node.js, though the README does not specify a version.

Can I use localtunnel with a custom domain?

Not as a fixed setup. The README describes random subdomains or requested names that may not be granted, so localtunnel is not a fit for a permanent custom domain.

Is localtunnel secure?

The README does not describe access restrictions or security features. Treat the public URL as open to anyone who has it, and avoid exposing sensitive services.

What are the alternatives to localtunnel?

Projects commonly compared with localtunnel include ngrok, Cloudflare Tunnel, serveo and localhost.run. This page does not compare their features, so check each project's documentation for your needs.

Why does my tunnel stop working?

The README says the tunnel stays active for the duration of your session. If your local server restarts, lt reconnects once it is back. If the tunnel closes, run the command again to get a new URL.

New agent skills, repos and AI tools — every week

The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.

Our verdict

localtunnel suits developers who need a quick public URL for a local app, webhook testing, or a temporary tunnel in automated tests. It is a poor choice for production hosting, fixed custom domains, or anything that needs guaranteed uptime or documented access controls.

Install options & downloads