bind-easy
Easily create UDP sockets and TCP servers that bind to ports.
npm install bind-easy
Usage
const bind = require('bind-easy')
const server = await bind.tcp()
const server = await bind.tcp(8080)
const server = await bind.tcp([8080, 8081, 8082])
const server = await bind.tcp([8080, 8081, 8082])
const server = await bind.tcp([8080, 8081, 8082], { allowAny: false })
const socket = await bind.udp([8080, 8081, 8082])
const { server, socket } = await bind.dual(8080)
API
server = await bind.tcp([ports], [{ allowAny }])
Bind a TCP server. Pass a range of ports to try.
If none of the ports work, bind to a random free one unless allowAny is set.
If only one port is specified, it will try nearby ports first.
socket = await bind.udp(...)
Same but for a UDP socket.
{ server, socket } = await bind.dual(...)
Same but for both a TCP server and UDP socket binding to the same port.
License
MIT