0

I would like to access my server that I host on my computer (Node.js & Express) from my phone. The computer is on the same network as the phone.

As soon as I type localhost:3000 in the address bar of the browser on the desktop PC, everything works without problems.

If I now try to open my site with the cell phone under the following address 192.168.0.100:3000, I get no error message but nothing is displayed... The IP address was retrieved with ipconfig.

I have tried several solutions that I have found here on Stack Overflow such as port sharing in the firewall settings. Unfortunately without success.

Here is my code when creating at the server:

var express = require('express');

var app = express();

var server = app.listen(process.env.PORT || 3000, listen);

function listen() {
  var host = server.address().address;
  var port = server.address().port;
  console.log('Example app listening at http://' + host + ':' + port);
}

When I try to check my IP address via the console.log, I get the following:

enter image description here

If someone has an idea what this could be I would be very happy!

#1 Update:

I have now replaced my line of code with

var server = app.listen(3000, "127.0.0.1", listen);

and I get the following back from my console:

enter image description here

I can access my server from my computer through

127.0.0.1:3000

localhost:3000

If I try to access (on computer) through 192.168.0.100:3000 nothing happens. I also get no error message. Only a white screen.

#2 Update:

Typing "ipconfig" in cmd

enter image description here

After changing the IP to

var server = app.listen(3000, "192.168.0.100", listen);

I could not access my server anymore. Not even using localhost:3000. However, when examining the item I found an error that does not show up when I set

var server = app.listen(3000, "127.0.0.1:3000", listen);

I do not understand why the error shows up when changing the IP address, since the code is the same.

Heres a picture of the error

enter image description here

Error fixing

Apparently one way to work around the error is to use a tunneling service (ngrok). I will try it

#3 Update

In my last attempt, i was trying to tunnel my server via ngrok. At first, everything looked like it was finally going to work. From my own PC I could access my websocket server via ngrok forwarding link. However, when I tried to click on the link with my phone/second pc, I got the error that the connection is refused...

enter image description here

If someone has an idea or an approach to what this could be, I would be very happy.

SOLUTION IS POSTED IN THE COMMENTS

4 Answers4

1

If you want to access your localhost over the internet...

There are some softwares / Chrome Extensions that let's you access your local host over the internet...

  1. https://ngrok.com
  2. http://localtunnel.me
  3. http://localhost.run

You can do Google search for more softwares like these ones and choose accordingly to your work.

JeX
  • 95
  • 1
  • 10
0

Sorry I can't comment:

Have you tried 192.168.0.100:3000 into the browser, on the computer?

As for the http://:::3000 you can check this

qUneTz
  • 3
  • 5
  • Hello , thank you for the feedback ! I replaced my line of code and now instead of http://:::3000 I get this http://127.0.0.1:3000 out. I posted the answer at #1 update. That looks a little clearer than me squeezing it into the comment here. – MasterKneater Nov 30 '22 at 21:44
  • Make sure that 192.168.0.100 is your IP on the LAN, Is IPv4 Address 192.168.0.100 when you type the ipconfig command in cmd? Be sure not to select the "Default Gateway" instead. Like this: `IPv4 Address. . . . . . . . . . . : 192.168.0.100` – qUneTz Nov 30 '22 at 22:55
  • And another thing, you should try as well: `var server = app.listen(3000, "192.168.0.100", listen);` The behavior that you describe is weird, when you say _If I try to access (on computer) through 192.168.0.100:3000 nothing happens. I also get no error message. Only a white screen._ have you tried to look into the network tab ( you should be able to see that once you open inspect element ) to see from where that response comes from? Check the response headers, maybe you'll find a clue. If not at least you'll find some interesting data :) – qUneTz Nov 30 '22 at 23:04
  • Hi qUneTz, thanks for the feedback! I checked the IP address again and it is 192.168.0.100 (See screenshot update #2). After changing the IP to var server = app.listen(3000, "192.168.0.100", listen); I could not access my server anymore. Not even using localhost:3000. However, when examining the item I found an error that does not show up when I set var server = app.listen(3000, "127.0.0.1:3000", listen);. I do not understand why the error shows up when changing the IP address, since the code is the same. I have added a screenshot of the error in my post under Update#2. – MasterKneater Nov 30 '22 at 23:28
0

I give up because new errors keep appearing. I thought I'd post my solution (or my new approach) here in case anyone else is in the same situation as me. In the end I used the following github repository as a base for my project. If I set up a server with this there are no problems at all. I have also tunneled it with ngrok in the end.

Link to Github

It also uses p5.js, node.js and socket.io

0

I think you cannot see in other devices because you are not sending anything to show. This code worked fine,

const express = require("express");
const app = express();
const http = require("http").createServer(app);
const port = process.env.PORT || 3000;

app.get("/", (req, res) => {
  res.send("Hello world");
});

http.listen(port);```