Node.js server only listening on ipv6

You need to specify an IPV4 address when you call the listen(), I had the same issue with the http module. If I use this:

var http = require('http');

var server = http.createServer(function(request, response) {
...
});

server.listen(13882, function() { });

It only listen on IPV6, as you can see from netstat output:

$ netstat -lntp
Proto  Recv-Q  Send-Q  Local Address  Foreign Address  State
tcp6        0       0  :::13882       :::*             LISTEN

However, if I specify an IPV4 address like this:

var http = require('http');

var server = http.createServer(function(request, response) {
...
});

server.listen(13882, "0.0.0.0", function() { });

netstat will report the server as listening on IPV4:

$ netstat -lntp
Proto  Recv-Q  Send-Q  Local Address     Foreign Address  State
tcp         0       0  0 0.0.0.0:13882   0 0.0.0.0:13882  LISTEN

I’m using Ubuntu 16.04 and npm 5.3.0.

HTH

Source: https://stackoverflow.com/a/48170565/4353123

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×