What is the difference between process.nextTick, setImmediate and setTimeout?

Node.js basics · Experienced

Model answer

process.nextTick runs its callback right after the current operation, before other queued work, and promise microtasks follow. setImmediate runs in the "check" phase after I/O. setTimeout(fn, 0) runs in the timers phase after at least the delay. Order between setTimeout 0 and setImmediate from the main module is not guaranteed, but inside an I/O callback setImmediate comes first. Overusing nextTick can starve I/O.

Learn this topic

What Is Node.js? Install It and Run Your First Script in the course Node.js and Express: Build a Back End API from Scratch.

Sign in to add your own answer.

More questions