Exposing Your Local Development Server to the Internet Using LocalTunnel in Node.js

LocalTunnel is a Node.js module that allows you to expose your local development server to the internet via a secure tunnel. This is useful when you need to share your work with someone else or when you need to test webhook integrations with external services.

Here’s a quick tutorial on using the LocalTunnel module in Node.js:

  1. Install LocalTunnel

First, you’ll need to install LocalTunnel globally on your system using npm. Run the following command in your terminal:

npm install -g localtunnel
  1. Start your local server

Before using LocalTunnel, make sure you have a local server running on your system. For this example, let’s assume you have a server running on port 3000.
Setting Up a Local Server in Node.js: A Step-by-Step Guide

  1. Create a tunnel

To create a tunnel to your local server, execute the following command in a new terminal (Make sure to keep the terminal where you started your server open.), replace <port> with the port number on which your local server is running (e.g., 3000):

lt --port <port>

For example:

lt --port 3000
  1. Get your public URL

Once you’ve run the above command, LocalTunnel will provide you with a public URL that you can share with others. The URL will look something like this:

your url is: https://randomsubdomain.loca.lt

Now, anyone with the provided URL can access your local server through the secure tunnel.

  1. Close the tunnel

When you’re done sharing your local server, you can close the tunnel by pressing Ctrl + C in your terminal.

Note: Keep in mind that the public URL is temporary and will change each time you create a new tunnel. If you need a custom subdomain, you can use the --subdomain flag when creating the tunnel:

lt --port 3000 --subdomain mycustomsubdomain

This will create a tunnel with a URL like https://mycustomsubdomain.loca.lt. However, custom subdomains are not guaranteed to be available, so choose a unique one to increase your chances of success.

Hello, I’m Anuj. I make and teach software.

My website is free of advertisements, affiliate links, tracking or analytics, sponsored posts, and paywalls.
Follow me on LinkedIn, X (twitter) to get timely updates when I post new articles.
My students are the reason this website exists. ❤️

Feedback Display