How can I access my nodejs-express localhost server from another computer in the same network?

YulePale picture YulePale · May 19, 2019 · Viewed 7.2k times · Source

I have tried this and this answers but I still cannot access my local host from another computer in the same network using express server.

I am running my express server from a windows 10 machine, I cannot access it when I type in my ip-address. I have tried:

  1. Disabling windows firewall.
  2. Accessing my IP address from my computer still doesn't work.
  3. Accessing from another device, an Ipad still doesn't work. Tells me the connection is not secure.

How can I solve this? (A step by step solution would really help, Thanks)

Answer

YulePale picture YulePale · May 24, 2019

Thanks to this and some other answers(can't get their links).

Follow the steps below:

  1. Find your local network's IP by go to cmd or press Winkey + R then type in "ipconfig". It will give out some information and your local IP should look like 192.168.1.x .If you are using ethernet choose the one under ethernet if you are using wi-fi choose the ine under wifi.
  2. go to your app.listen part of the code and put the code to look as below:

    //For some reason it only works on port 80.
    app.listen('80','192.1xx.x.x59', () => {
        console.info(`server started on port 80)`);
    });
    
  3. To view it from other computers, you need do http:// or http://myPcsName if that doesnt work.

  4. Finally if it works then after restarting your sever it doesn't, then your computer or network has changed the ip address so you need to do step one again to get your new ip address.

If you understand why For some reason it only works on port 80 and why the ip address changes on server restart please let us know in the comments. Thank you.