Last active
February 3, 2016 18:13
-
-
Save Flackus/3c995cd735c44425c391 to your computer and use it in GitHub Desktop.
Find unused port in node.js
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
#!/usr/bin/env node | |
'use strict'; | |
const net = require('net'); | |
const server = net.createServer(); | |
let port; | |
server.listen(0, () => { | |
port = server.address().port; | |
server.once('close', () => { | |
console.log(`Found unused port: ${port}`); | |
}); | |
server.close(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment