I'm having a tough time writing a test for a feature intended to be in a live reload developer environment. Basically I'd like to
- Start a dumb server on localhost:9876
- Close it
- Start it again on the same host and port
- Close it again
But upon starting it again I get a EADDRINUSE error, despite closing the server and dereferencing it.
Here's my code so far:
const net = require('net');
const server = net.createServer();
server.listen(9876, 'localhost');
server.close(() => {
server.unref();
const anotherServer = net.createServer();
anotherServer.listen(9876, 'localhost');
});
I'm guessing that it has something to do with me not sure of the inner workings of the node TCP Server...