How can I allow other users to access my application that is running on localhost? Is there any package in the npm that facilitates this access?
2 Answers
To access your localhost (on a home network) from the internet, you need to provide a couple things.
You need a way for your clients to contact your server. This can either be via an IP address
http://xxx.yyy.xxx
or a domain namehttp://somedomain.com/whatever
. If it's an IP address, then it needs to be a public IP address (not a local network address). For a home network, you would typically use the public IP address of your router that is how you connect to the internet.If you are going to use a domain name, then you need to actually choose a domain name, register it with a registrar and configure it to point to your router's public IP address.
If your router does not have a static IP address, then you will likely need to use a dynamic DNS service that will automatically update your DNS entry to point to your dynamic IP address whenever (or if ever) it changes. There are lots of dynamic DNS services.
Then, you need to create a "hole" in your router's firewall so that incoming connections to port 80 are port forwarded to the computer where your server is running. This will typically be done in the router's configuration/security administration UI. You will "port forward" and incoming request on port 80 to whatever IP and port your server process is running on your local network.
For a more durable server installation, you would do the following:
Buy a hosting package at a hosting site that hosts the type of application you are running at the scale you expect to run it at (storage, CPUs, bandwidth). In your case, you'd be looking for a hosting service for node.js apps.
Then, you'd buy a domain name and configure it to point to the public IP address that your hosting provider gave you for your server.
Then, you'd install your server app at the hosting site and run it according to the hosting provider's instructions.
Then, a user can access your server via an URL using your public domain
http://somedomain.com/whatever
.

- 683,504
- 96
- 985
- 979
-
thx. You cleared my ideas. Now, i've to find a tutorial to do the first 3. and first 4. paragraphs. Do you have any link? – Joao Albuquerque Dec 12 '17 at 03:51
-
1@JoaoAlbuquerque - There are hundreds of articles on port forwarding from your home network. The router config is specific to your brand of router, but there are many articles on the general topic. Here's one article: [How to access a home server behind a router/firewall](https://lifehacker.com/127276/geek-to-live--how-to-access-a-home-server-behind-a-routerfirewall). There are many others you can find with Google. – jfriend00 Dec 12 '17 at 03:56
You can do so by using ngrok
. In your command prompt type npm install ngrok
. Once installation finished restart your command prompt and type ngrok http 3000
, here 3000 is the port on which your server is running. You will get something like http://ee309.ngrok.io
which is your temporary domain. You can use it until you shut your system down or close command prompt.

- 131
- 3
- 13
-
Is there another way to do this without ngrok and similar packages? For example: I want to run the app on my machine and other people would access it by an ip. Once an instructor showed me, but id did not remember – Joao Albuquerque Dec 12 '17 at 02:00
-
I have also tried but nothing works for me. Anyway please check with this link https://stackoverflow.com/questions/14043926/node-js-connect-only-works-on-localhost – Nandha Kumar Dec 12 '17 at 02:03