我想回想一下readline。 怎么做?

我想回想一下

rl.question("input your port do you want (about 0 - 65535) : ", function(portnumber) 

在这之后:

 if(netinfo > 6665){ return console.log("Error stupid i say about 0 - 65535") } rl.question("input your port do you want (about 0 - 65535) : ", function(portnumber){ if(netinfo > 6665){ return console.log("Error stupid i say about 0 - 65535") } netinfo = portnumber; const requestHandler = (request, response) => { console.log(request.url) response.write('<b>welcome to groone simple http server :p </b>'); response.end('ahahahahahah :)'); } 

怎么做?

我看到的唯一方法是recursion:

 (function restart(){ rl.question("input your port do you want (about 0 - 65535) : ", function(portnumber){ if(portnumber > 6665){ console.log("Error stupid i say about 0 - 65535"); return restart(); } //... }); })() 

当我们收到正确的/预期的答案时,你需要一个无限循环。

示例代码:

 var correctAnswer = false; while(!correctAnswer){ doStuff() if(0 < receivedAnswer && receivedAnswer < 6665) correctAnswer = true; }