Tunnel the internet to your local services
There are times when we need to expose our local services to the internet. This is possible with a Ngrok alternative called LocalTunnel, a npm package.
Give this blog post a like, it helps support my content, thank you! 🙏
Why?
There are times when you want to expose your local services temporarily to the internet for the outside World to reach. For example, you might be adding a payment integration to your app with Stripe or LemonSqueezy and you need the test webhooks. These would need to be sent to your local development server because you don’t want to deploy to your staging environment for every test or code change.
How? Quickstart
There are various tools out there to do this, the most famous being Ngrok. But I really like the simplicity of the alternative LocalTunnel.
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.
Installation
Note: you need Nodejs installed.
Install the npm package globally:
npm install -g localtunnel
Running
If you are running a project or service locally like NextJS on port 3000, you can run the command in your terminal with the port flag:
lt --port 3000
In your terminal this will output a domain you can use to route external traffic on the internet to your local services:
your url is: https://dull-readers-call.loca.lt
Note: this url will change every time. Here I will stop the command and run it again and you will notice the url has changed:
Extra settings
Run the help command to get all available options:
lt --help
Here is the output from the help command:
Usage: lt --port [num] <options>
Options:
-p, --port Internal HTTP server port [required]
-h, --host Upstream server providing forwarding
[default: "https://localtunnel.me"]
-s, --subdomain Request this subdomain
-l, --local-host Tunnel traffic to this host instead of localhost,
override Host header to this host
--local-https Tunnel traffic to a local HTTPS server [boolean]
--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 for your local HTTPS
server (ignore cert/key/ca options) [boolean]
-o, --open Opens the tunnel URL in your browser
--print-requests Print basic request info [boolean]
--help Show this help and exit [boolean]
--version Show version number [boolean]
You can also use LocalTunnel programmatically if you need, see the API section in their docs.
Conclusion
Yes there are more advanced alternatives but if you don’t need a specific feature (for example, custom domains or sub domains), then I think the LocalTunnel library is perfect for what we require as developers 99% of the time.
It is:
simple
open source
free
npm package https://www.npmjs.com/package/localtunnel
Let me know in the comments which tools you have tried and what you liked and didn’t like about them below. 👇
If you prefer to watch a video on this topic: