Cannot start my Node.Js application with my computer IP, but can with localhost

So, I have a node js application configured to listen on port 5050 of my machine:

So, when I go to http: // localhost: 5050 / myapp , my application loads fine. I use the express framework, so my work with frames is as follows:

var server = app.listen(5050, '0.0.0.0', function () {
    console.log("App started on port 5050")
});

I also did netstat (Am using a Windows 10 machine), and there is no postback, no loopbacks for the local IP address.

However, when I run my ip machines, for example. http://192.168.0.231:5050/myapp I keep getting: this site cannot be reached

EDIT: I don't think I was very clear.

My firewall is disabled, I tried without the IP address specified in app.listen. I don’t think this is a problem with the code, because when I try to use only a simple test application and try to run it with an IP address, it’s also time

+4
source share
2 answers

Try listening with no ip parameter

var server = app.listen(5050, function () {
   console.log("App started on port 5050")
});  
0
source

When starting the nodejs application, I also ran into the same issue you were talking about. Before my code looks like this.

var express = require('express');
var app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var mongoChat = require('./app/mongo_chat');

var ip = "127.0.0.1";
var port = 3000;
var users = {};
var WhisperChek = false;
var storage=[];
app.use(express.static(__dirname + '/public'));
app.get('/', function (req, res) {
    res.sendfile('index.html');
});
//socket connection
    io.on('connection', function (socket) {
        //console.log('Someone connected!');
        mongoChat.mognolizer(io,socket, users, WhisperChek);
        function updateNicknames() {
            io.emit('nickname', Object.keys(users));
        }
//disconnect socket
        socket.on('disconnect', function (data) {
            if (!socket.Username)return;
            delete users[socket.Username];
            updateNicknames();
        });
    });
http.listen(port,ip, function () {
    console.log('listening on *:3000');
});

But I removed var ip="127.0.0.1"from the code and updated the listening function as:

http.listen(port, function () {
        console.log('listening on *:3000');
    });

localhost, .. localhost:3000, ipaddress, .. ipaddress:3000. , ip 127.0.0.1, localhost, ipaddress, , , . , , .

0

Source: https://habr.com/ru/post/1658353/


All Articles