I'll be very specific here in the hope that folks who understand this can edit to rephrase to the general situation.
Currently when you run "node debug", it spawns a process to listen on port 5858. Then in the parent, a connection is attempted to that port.
However if you have another "node debug" session running, currently "node debug" hangs because that port is in use.
Specifically the message you see is:
$ node debug example/gcd.js 3 5
< debugger listening on port 5858 >
connecting...
Better would be for it to detect that the port is in use (without a connecting to it which might mess up another client that is trying to connect that existing debugger).
Edit: The accepted solution is now in trepan-ni and trepanjs.
See also Node JS - How Can You Tell If A Socket Is Already Open With The Einaros WS Socket Module?
Use inner http module:
const isPortFree = port =>
new Promise(resolve => {
const server = require('http')
.createServer()
.listen(port, () => {
server.close()
resolve(true)
})
.on('error', () => {
resolve(false)
})
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With