mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2024-12-20 12:32:26 -05:00
4d5dbb118e
* automatic port "discovery" for packets and server tests * Semi-colon begone! * move getport to commons file - u9g * Merge code
12 lines
290 B
JavaScript
12 lines
290 B
JavaScript
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 }
|