Created
August 27, 2018 13:56
-
-
Save marverix/79c44a18f9f86fc4685ed1d6b59cd6f5 to your computer and use it in GitHub Desktop.
Node.js - Sync check if local port is available (linux only!)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { execSync } = require('child_process'); | |
module.exports = function(port) { | |
try { | |
execSync('nc -z 127.0.0.1 ' + port); | |
} catch(e) { | |
return true; | |
} | |
return false; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment