Home »
Node.js
Node Timer Module
Node time module: Here, we are going to learn about the Node Time modules with the examples.
Submitted by Godwill Tetah, on June 02, 2019
Node modules are like libraries which help us perform specific tasks. Node.js is always considered powerful because it has a very large ecosystem of third-party modules.
The Timer module is a built-in module used to perform time-related tasks or functions to be executed after a particular period of time.
Take Note! You should have Node js in your PC.
With Node.js already up and running, let's get started.
Now, let's get started.
The Timer module is an object where we equally make use of its various properties to perform various tasks...
For example, assume we wish to print out INCLUDEHELP! Many times on the console.
It'll be stressful using console.log ().
We can make use of the timer module to print INCLUDEHELP! every 2 seconds.
Below, is a code example.
Open a text editor and type the following code and save it with the file name app.js:
var x = setInterval(function () {
console.log("INCLUDEHELP");
}, 2000);
Note:
- 2000 is used for 2 seconds. In most time-related programs, seconds are almost written as thousands.
- The file should be saved in your default Node.js directory.
Run the code by initiating the file at the command prompt like a regular Node.js file.