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");
});
server.listen(7777);
I start it with node server.js
and then close it with Ctrl + Z on Mac. When I try to run it again with node server.js
I get this error message:
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: listen EADDRINUSE
at errnoException (net.js:670:11)
at Array.0 (net.js:771:26)
at EventEmitter._tickCallback (node.js:192:41)
Am I closing the program the wrong way? How can I prevent this from happening?
fg
after Ctrl-Z, you'll be back where you left off. So your earlier node is still running. Watch out if you're doing this for other commands too! – ruffinCtrl+Z
action, a proper methodology could befg
to revive the process, and thenCtrl+C
to kill it proper. – Metagrapher