I am very new to node.js and first thing that I could not easily google is following. Consider the most typical node.js example:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');
How will node.js know that it should not exit after last line has executed? Coming from .NET I have a simplified assumption that the process exits when all of its non-background threads are terminated. As node.js is single-threaded, I believe that there should be some logic monitoring event subscriptions which will decide whether there are still events which may be triggered, or otherwise node.js can terminate. Unfortunately, I could not find any docs on that. Could anyone help?