• Thursday, August 29, 2019

    An Introduction to Node.js Timers



    If you are a little familiar with the concept of Node.js, you must be quite familiar with the concept of Node.js timers too. In node.js, timers are used to schedule a certain event, which then executes at a certain time which has been set by the timer. You can node js tutorial for beginners to get more insight into the concept of timers in node.js.

    Mainly, there are five major methods in the timers module of Node.js which demonstrate how any event is scheduled to be triggered. These five methods are:

    setInterval: setInterval is a method of node.js timers module which repetitively executes the events. This method defines a certain time interval after which any specific event must be executed. There are two arguments included in the setInterval() method, the event to be scheduled and the time interval to set for the event.


    setTimeout: setTimeout method in node.js timers is used to set any event to be executed at a certain time period. There are two arguments passed in the setTimeout() method, the first argument constitutes of the event to be executed and the second argument consists of time at which event is set to be triggered.


    SetImmediate: SetImmediate method in node.js timers defines that the event will execute after the current process being executed but before the next timer loop. The method contains one argument as the event which will be executed immediately after calling this method.

    clearInterval: The clearInterval method in node.js timers is used to clear the timer which has been set by the setInterval() method. Also, the id which is associated with the setInterval() method is used to clear the timer set by the method.

    clearTimeout: The clearTimeout() method is used to clear the timer set by clearTimeout() method in node.js.

    clearImmediate: The clearImmediate() object is used in node.js to clear the timer set by SetImmediate() method.

    Now, you must have been familiar with how an event is triggered or scheduled while working in node.js. You can also see node.js interview questions for more insights into the timers concept. Note that using the timers event in node.js is a very useful concept as it can be used to sort the asynchronous feature of node.js triggering event.

    No comments:

    Post a Comment