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:
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:
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
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
If someone has an idea or an approach to what this could be, I would be very happy.
CodePudding user response:
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
CodePudding user response:
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...
You can do Google search for more softwares like these ones and choose accordingly to your work.