avatarRahul Banerjee

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

1956

Abstract

sting your project on other devices: You might want to test your React project on an actual mobile or any other device.</li><li>Making your server accessible to others: Exposing your localhost URL will let anyone with the URL access it. This can help you to share your server/React project with others for feedback or debugging.</li></ul><p id="3dd0">We will look at two free options to expose your localhost URL. The first option will require you to download software while the second option will require an NPM package.</p><h1 id="1a12">Option 1: Ngrok</h1><p id="9ccd">You will need to sign up for <a href="https://ngrok.com/">ngrok</a>. After you sign up, you will have to download the software.</p><figure id="0b55"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*7Ezb7lPQiaZzGJEy.png"><figcaption>Screenshot of ngrok homepage</figcaption></figure><p id="83bf">After the download is complete, unzip the file. Remember the directory where you unzipped the file. This will be needed in the next step.</p><p id="1555">Open a terminal and navigate to the location of the unzipped file using the ‘cd’ command. Once your terminal is at the directory with the unzipped file, type the following command:</p><div id="1805"><pre>ngrok http <PORT <span class="hljs-built_in">NUMBER</span>></pre></div><p id="43f4">If your React project is running on port 3000, you’d have to type the following:</p><div id="c8e8"><pre><span class="hljs-attribute">ngrok</span> http <span class="hljs-number">3000</span></pre></div><figure id="9902"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*h1flsuQZQVgFTYaX.png"><figcaption>Screenshot of Terminal after running ngrok</figcaption></figure><p id="e844">You should see a similar output in your terminal. The public URL is the URL next to ‘Forwarding.’ In my case it is <a href="http://35cc-69-58-102-156.ngrok.io/">http://35cc-69-58-102-156.ngrok.io</a>. If you access your public U

Options

RL, you should see the same thing you see when you access your localhost URL. Note the value next to ‘Session Expires.’ After the allotted time, the public URL will expire, and you will have to generate a new URL.</p><h1 id="3185">Option 2: Localtunnel</h1><p id="de01"><a href="https://localtunnel.github.io/www/">Localtunnel</a> is an npm package that can be installed using a node. Type the following command to install it:</p><div id="fc97"><pre>npm <span class="hljs-keyword">install</span> -g localtunnel</pre></div><p id="edb0">We use the <code>-g</code> tag to install it globally so it can be accessed by multiple projects. After installation is complete, type the following command to expose your localhost URL:</p><div id="997b"><pre>lt <span class="hljs-comment">--port 3000</span></pre></div><p id="85d1">If successful you should see a similar URL as the following:</p><div id="4ad7"><pre>your url <span class="hljs-keyword">is</span>: https:<span class="hljs-comment">//fast-cow-24.loca.lt</span></pre></div><p id="0b03">If you get the following error message</p><div id="0764"><pre><span class="hljs-keyword">command</span> not found: <span class="hljs-keyword">lt</span></pre></div><p id="c92b">Locate where the node installed the package. It should be inside a node modules folder. Once you find the node modules folder, cd to the following:</p><div id="f16c"><pre><span class="hljs-built_in">cd</span> node_modules/localtunnell/bin</pre></div><p id="3283">and type the following:</p><div id="33ed"><pre><span class="hljs-string">./lt.js</span> <span class="hljs-params">--port</span> 3000</pre></div><p id="7211">If you are looking for a more detailed article on exposing localhost URLs, I recommend <a href="https://chenhuijing.com/blog/tunnelling-services-for-exposing-localhost-to-the-web/#%F0%9F%91%9F">this article</a>.</p><p id="c5cd">Connect with me on <a href="https://twitter.com/rahulbanerjee99">Twitter</a>.</p></article></body>

How To Expose Your Local Host URL as a Public URL

There might be times when you wish to access your API or React project using a public URL but do not want the hassle of deploying it

Photo by Aaron Burden on Unsplash

Basically, instead of http://127.0.0.1:5000/, you’d want something like http://35cc-69-58-102-156.ngrok.io so that others could access it as well. This article will talk about two ways you can do so.

What Does It Mean To Expose Your Localhost URL?

  • First of all, it is temporary. Unless you opt for a paid option, most public URLs will expire in a few hours. You can always generate a new one.
  • The exposed URL will basically be in sync with your localhost URL. Any requests made to your localhost URL will also be made to the exposed URL and vice versa.
  • Your public URL will only be active as long as your local API or React Project is active.

Why Would You Want To Expose Your Localhost URL?

  • Working with Webhook: Webhooks require a public URL. Exposing your localhost URL generates a public URL for you. The Webhook request can be made to this public URL and your localhost URL will also receive the request. Check out this article to learn more about webhooks and how to use them with Python.
  • Testing your project on other devices: You might want to test your React project on an actual mobile or any other device.
  • Making your server accessible to others: Exposing your localhost URL will let anyone with the URL access it. This can help you to share your server/React project with others for feedback or debugging.

We will look at two free options to expose your localhost URL. The first option will require you to download software while the second option will require an NPM package.

Option 1: Ngrok

You will need to sign up for ngrok. After you sign up, you will have to download the software.

Screenshot of ngrok homepage

After the download is complete, unzip the file. Remember the directory where you unzipped the file. This will be needed in the next step.

Open a terminal and navigate to the location of the unzipped file using the ‘cd’ command. Once your terminal is at the directory with the unzipped file, type the following command:

ngrok  http <PORT NUMBER>

If your React project is running on port 3000, you’d have to type the following:

ngrok http 3000
Screenshot of Terminal after running ngrok

You should see a similar output in your terminal. The public URL is the URL next to ‘Forwarding.’ In my case it is http://35cc-69-58-102-156.ngrok.io. If you access your public URL, you should see the same thing you see when you access your localhost URL. Note the value next to ‘Session Expires.’ After the allotted time, the public URL will expire, and you will have to generate a new URL.

Option 2: Localtunnel

Localtunnel is an npm package that can be installed using a node. Type the following command to install it:

npm install -g localtunnel

We use the -g tag to install it globally so it can be accessed by multiple projects. After installation is complete, type the following command to expose your localhost URL:

lt --port 3000

If successful you should see a similar URL as the following:

your url is: https://fast-cow-24.loca.lt

If you get the following error message

command not found: lt

Locate where the node installed the package. It should be inside a node modules folder. Once you find the node modules folder, cd to the following:

cd node_modules/localtunnell/bin

and type the following:

./lt.js --port 3000

If you are looking for a more detailed article on exposing localhost URLs, I recommend this article.

Connect with me on Twitter.

Programming
Software Development
Software Engineering
Coding
Data Science
Recommended from ReadMedium