A simple node program with one line of code exits immediately after all the code runs:
console.log('hello');
However, the HTTP server program listening on the port does not exit after all the code has been executed:
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');
So my question is, what did it mean? What made the first program exit after all the code was executed, and the second program continues to live?
I understand that in Java, the specification says that when exiting the last thread of a non-daemon, the JVM shuts down. So what is the mechanism in the nodejs world?
source
share