Files
commonroutesApp/www/lib/ui-leaflet/grunt/utils/getAvailPort.js
2017-01-27 17:49:04 +01:00

24 lines
545 B
JavaScript

var exec = require('shelljs').exec;
var isWin = /^win/.test(process.platform);
var isPortOpen = function (port) {
var cmd;
if (isWin)
cmd = 'netstat -an | find /i ":' + port + '" | find /i "listening"';
else
cmd = 'lsof -i:' + port + " | tail -n 1 | awk '{print $2}'";
var portResponse = exec(cmd, {
silent: true
}).output;
return portResponse ? false : true;
}
module.exports = function (startPort) {
while (!isPortOpen(startPort)) {
startPort += 1;
}
return startPort;
}