I have a simple TCP server that listens on a port.
var net = require(\"net\"); var server = net.createServer(function(socket) { socket.end(\"Hello!\\n\"
To end the program, you should be using Ctrl + C. If you do that, it sends SIGINT, which allows the program to end gracefully, unbinding from any ports it is listening on.
SIGINT
See also: https://superuser.com/a/262948/48624