According to the documentation:
setTimeout()
can be used to schedule code execution after a designated amount of milliseconds. This function is similar to window.setTimeout()
of the browser’s Javascript API, however, a code string cannot be passed to be executed.
setImmediate()
will execute the code at the end of the current event cycle cycle. This code will be executed after any I/O operation in the current event loop and before any timers scheduled for the next event loop. This code execution can be thought of as occurring "soon after", meaning that any code after the function call setImmediate()
will be executed before the function argument setImmediate()
.
If there is a code block that must be run several times, setInterval()
can be used to execute this code. setInterval()
takes a function argument that will be executed an infinite number of times with a delay of milliseconds given as the second argument. As well as setTimeout()
, additional arguments can be added beyond the delay, and these will be passed to the function call.
At a glance in that video from White Rodrigo on Node.js timers