How to access localhost from the Internet?
Tags: webdev, testing, beginners, javascript
Published: 2021-03-26 04:13:50

Suppose you are working on a hobby project or building projects locally for learning few concepts. Once, you complete the project, and it works as expected, you might feel excited about sharing it with your friends and colleagues.

However, you don’t want to get into the pain of hosting it on a web server as it involves buying a domain name, hosting space, and various other configurations.

Now, some of you might suggest that use the port forwarding option. For those who are unaware of port forwarding, it is a process of intercepting data traffic headed for a computer’s IP/port combination and redirecting it to a different IP and/or port.

I am sure you want to access your localhost from the internet without the hassle of port forwarding & hosting your application on a web server. Don’t you?

# Access localhost from the Internet

You can access localhost from the internet using a couple of services for free. Some of them that we are going to talk about in this blog post are:

1. [https://ngrok.com](https://ngrok.com)
2. [http://localtunnel.me](http://localtunnel.me)
3. [http://localhost.run](http://localhost.run)

We can use either of them to achieve our end goal. I have used ngrok and find it easy to set up and use. Actually, there is nothing as such to set it up.

If you’re a Windows user, you just need to download the binaries from ngrok.com and run it.

# ngrok.com

ngrok (pronounced as “en-grok“) gives you a public URL for the web app running on localhost.

It is a reverse proxy software that establishes secure connections from a public endpoint to a locally running service.

There are two ways to use ngrok:

* Download the software from the official website
* Use npm to install

Visit the [official docs](https://ngrok.com/docs) for more information.

### Steps to download & use:

1. Visit ngrok.com
2. Download ngrok
3. Extract the zip files and double click ngrok.exe

Once, you set up ngrok and execute it, there will be a command prompt as shown below:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f4i3o7kdx3ls4axnlzwf.PNG)

# localtunnel.me

Localtunnel will assign you a unique publicly accessible URL that will proxy all requests to your locally running webserver.

In order to use localtunnel you need nodejs installed on your machine.

To install localtunnel globally:

```
npm install -g localtunnel
```

To start the webserver on port 80:

````
lt --port 8000
```

To use port 3000:

```
lt --port 3000
```

#localhost.run

localhost.run is a client-less tool to instantly make a locally running application available on an internet-accessible URL. It doesn’t require us to install anything on our machine.

Simply, you can go to command prompt and execute the command given below:

````
ssh -R 80:localhost:8080 localhost.run
```

Note: To open a command prompt, you can press Windows + R keys (⊞ Win + R), then type “cmd” and click on Enter.

If your application is running on local port 3000, then use this command:

````
ssh -R 80:localhost:3000 localhost.run
```
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3eiatq16gtdgnpnogmce.PNG)

With the help of these three services, you can access localhost from the internet. You may figure out the one that works best for you and enjoy sharing your publicly accessible URL among your friends.

This is my localhost reactjs app that is now exposed over the internet using ngrok service.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kt1921pm5smas9k6beak.PNG)

#Closing Notes

This is a great utility for all the devs out there. Now, whatever web apps you build on your local system can be shared across with such ease.

Now, you know to access localhost from the internet, please share it with your friends and colleagues to educate them as well.

You may check our post on 👉 [Getting started with Deno](https://dotnetcrunch.in/getting-started-with-deno/)

Please visit our YouTube channel 👉 [DotNetCrunch](https://www.youtube.com/channel/UCXjb2EQf9pGQd6LlF1m6d_w)

Happy Learning!