You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
545 B

  1. var exec = require('shelljs').exec;
  2. var isWin = /^win/.test(process.platform);
  3. var isPortOpen = function (port) {
  4. var cmd;
  5. if (isWin)
  6. cmd = 'netstat -an | find /i ":' + port + '" | find /i "listening"';
  7. else
  8. cmd = 'lsof -i:' + port + " | tail -n 1 | awk '{print $2}'";
  9. var portResponse = exec(cmd, {
  10. silent: true
  11. }).output;
  12. return portResponse ? false : true;
  13. }
  14. module.exports = function (startPort) {
  15. while (!isPortOpen(startPort)) {
  16. startPort += 1;
  17. }
  18. return startPort;
  19. }