Search code examples
node.jsfedoranodejs-server

NodeJS + Fedora 32 refused to connect


Simplest server (same result with '0.0.0.0' and removing this property)

const http = require('http');

function handleRequest(a,b) {
    console.log('!');
}

var server = http.createServer(handleRequest);

server.listen(4000, '0.0.0.0',  function(){
    console.log("Server is listening");
});

Netstat:

sudo netstat -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      669/sshd: /usr/sbin 
tcp        0      0 0.0.0.0:4000            0.0.0.0:*               LISTEN      5631/node           
tcp6       0      0 :::22                   :::*                    LISTEN      669/sshd: /usr/sbin 

Result by accessing http://(server's IP):4000

This site can’t be reached (server's IP) refused to connect.


Solution

  • Ok, so I had to open port in firewall like this:

    firewall-cmd --zone=public --add-port=4000/tcp