The Timers module in Node.js contains functions that execute code after a set period of time.
- setTimeout/clearTimeout – can be used to schedule code execution after a designated amount of milliseconds
- setInterval/clearInterval – can be used to execute a block of code multiple times
- setImmediate/clearImmediate – will execute code at the end of the current event loop cycle
- process.nextTick – used to schedule a callback function to be invoked in the next iteration of the Event Loop
function cb(){
console.log('Processed in next iteration');
}
process.nextTick(cb);
console.log('Processed in the first iteration');
Output:
Processed in the first iteration
Processed in next iteration