node-minecraft-protocol/test/common/util.js

13 lines
290 B
JavaScript
Raw Normal View History

const net = require('net')
const getPort = () => new Promise(resolve => {
const server = net.createServer()
server.listen(0, '127.0.0.1')
server.on('listening', () => {
const { port } = server.address()
server.close(() => resolve(port))
})
})
module.exports = { getPort }