QPTR QPTR -3 years ago 253
Node.js Question

RangeError: "port" argument must be >= 0 and < 65536

I have an application written in electron and nodejs that I am trying to run. It uses the module portscanner to check for an open port in a particular range:

portscanner.findAPortNotInUse(3000, 3010, '127.0.0.1', function(error, port) {
console.log("Free port: " + port)

})


However, I am getting this error:

RangeError: "port" argument must be >= 0 and < 65536
at assertPort (internal/net.js:17:11)
at Server.listen (net.js:1389:5)


Even though the range I have is clearly less than 65536 and greater than 0.

Looking online, it seems to be an error in node v6 (I have v6.5.0). I am new to nodejs, and would greatly appreciate any help regarding how to fix this. Thanks.

Answer Source

If you are getting ADDRINUSE or similar errors, make sure your program is exiting cleanly. You could also try the kill command or use pm2.

But if you really need to look for a port, can you post the rest of the code? It says the error is in the server.listen. Are you sure you started listening after the findAPortNotInUse came back?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download