Since many node.js scripts follow a pattern of doing something asynchronously (example below), how do they know when to stop?
In the following code, how does node determine after processing the writeFile, and registering the callback appropriately, that the process should be kept alive until the callback(s) run?
fs = require('fs');
fs.writeFile('foo', 'cat', function() {
console.log('wrote to foo!');
fs.readFile('foo', 'utf8', function(err, data) {
console.log(data);
});
});