Tutorials References Menu

Node.js Timers Module

❮ Built-in Modules


Example

Write "Hello" every 500 milliseconds:

var myInt = setInterval(function () {
    console.log("Hello");
}, 500);
Run example »

Definition and Usage

The Timers module provides a way scheduling functions to be called later at a given time.

The Timer object is a global object in Node.js, and it is not necessary to import it using the require keyword.


Timers Methods

Method Description
clearImmediate() Cancels an Immediate object
clearInterval() Cancels an Interval object
clearTimeout() Cancels a Timeout object
ref() Makes the Timeout object active. Will only have an effect if the Timeout.unref() method has been called to make the Timeout object inactive.
setImmediate() Executes a given function immediately.
setInterval() Executes a given function at every given milliseconds
setTimeout() Executes a given function after a given time (in milliseconds)
unref() Stops the Timeout object from remaining active.

❮ Built-in Modules