Are there significant differences between the Chrome browser event loop versus the node event loop?

...when I make a call using Node's file and web i/o libraries, these are things that happen outside the stack whose callbacks are queued in a task queue?

Yes, absolutely; they're asynchronous just like Ajax and setTimeout are asynchronous. They perform some operation outside of the call stack, and when they've finished that operation, they add an event to the queue to be processed by the event loop.

Node's API provides a kind of asynchronous no-op, setImmediate. For that function, the "some operation" I've mention above is "do nothing", after which an item is immediately added to the end of the event queue.

There is a more powerful process.nextTick which adds an event to the front of the event queue, effectively cutting in line and making all other queued events wait. If called recursively, this can cause prolonged delay for other events (until reaching maxTickDepth).


Both are quite different. Browser's event loop doesn't depends on I/O Operations. But Node js event loop depends on I/O operations. Here the Node js event loop main goal is to separate out the main process and try to execute I/O operations and other timer API's asynchronously.

And another difference is we don't have a function setImmediate() in Browser. Difference between setTimeout() and setImmediate() is In setTimeout() call back function will execute after the given minimum threshold value in milliseconds. But in setImmediate() once any I/O Operation is done, if particular code is given inside setImmediate(), it will be executed first.

Because normally

setTimeout(() => {
    //some process
}, 0);

and

setImmediate(() => {
    //some process
});

are same and we can't predict which will execute first. But in Node js perspective under nodejs event loop mechanism if both are present under the callback of any I/O Operation, setImmediate() will get executed first. so,

let fs = require('fs');
fs.readFile('/file/path', () => {
   setTimeout(() => {
      console.log('1');
   }, 0);
   setImmediate(() => {
      console.log('2');
   });
});

The output for above code will be,

2
1