setinterval nodejs code example

Example 1: settimeout node js

setTimeout(function () {
    console.log("5 secondes"); 
}, 5000); 
console.log("now");

Example 2: js do every x seconds

window.setInterval(function() {
  // do stuff
}, 1000); // 1000 milliseconds (1 second)

Example 3: setinterval nodejs

setInterval(function () {
    console.log("Every 5 secondes"); 
}, 5000); 
console.log("now");

Example 4: setinterval vs settimeout js

var intervalID = setInterval(alert, 1000); // Will alert every second.
// clearInterval(intervalID); // Will clear the timer.

setTimeout(alert, 1000); // Will alert once, after a second.
setInterval(function(){ 
	console.log("Oooo Yeaaa!");
}, 2000);//run this thang every 2 seconds