Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 819
QPTR Avatar asked Nov 27 '22 18:11

QPTR


1 Answers

It's an issue with newer versions of node.

https://github.com/FWeinb/nodeshot/issues/11

It was also raised as an issue on the electron project.

For quickly handle it you can also use try.....catch

like image 138
abdulbarik Avatar answered Dec 04 '22 07:12

abdulbarik