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\"
Though this is a late answer, I found this from NodeJS docs:
The 'exit' event is emitted when the REPL is exited either by receiving the
.exitcommand as input, the user pressingtwice to signal SIGINT, or by pressing-C to signal 'end' on the input stream. The listener callback is invoked without any arguments.-D
So to summarize you can exit by:
.exit in nodejs REPL.-C twice. -D . process.exit(0) meaning a natural exit from REPL. If you want to return any other status you can return a non zero number. process.kill(process.pid) is the way to kill using nodejs api from within your code or from REPL.