INNER CODE UNIT · JavaScript
getAvailablePort
alohe/quicky · index.js:462
async function getAvailablePort(port) {
let current = port;
while (await isPortInUse(current)) {
const answer = await inquirer.prompt([
{
type: "input",
name: "port",
message: `Port ${current} is already in use. Please enter another port:`,
validate: (input) => {
const n = Number.parseInt(input, 10);
return Number.isInteger(n) && n > 0 && n <= 65535
? true
: "Please enter a valid port number (1-65535).";
},
},
]);
current = Number.parseInt(answer.port, 10);
}