What is the difference between process.nextTick() and setImmediate()?
process.nextTick queues a callback to run before the event loop continues to the next phase, ahead of promise microtasks. setImmediate schedules the callback for the check phase of the next iteration. nextTick therefore always runs sooner, and recursive nextTick calls can starve the event loop entirely, which is why setImmediate is the safer default for deferring work.