Get the current listening port of the server object via server.address():
var s = net.createServer(...)
s.listen(...)
... s.address().port
But note the warning: Don't call server.address() until the 'listening' event has been emitted.
So, you really need something like:
s.listen(PORT, function () {
console.log('Server listening on port: ' + s.address().port);
});
(via)
Killing and restarting the server is annoying, enter nodemon which will "reload, automatically" (via).
Install via:
sudo npm install -g nodemon
Then instead of running node you run nodemon a la:
nodemon server.js
Learned today that the technique I used for my Arduino VNC server (and had intended to use here) is actually called "display list rendering". (via "Display list rendering")