how to delay execution in nodejs 1

how to delay execution in nodejs

function sayHello() {
  console.log("hello");
}

// calls the sayHello function after 1000 milisecends
setTimeout(sayHello, 1000);

Here is what the above code is Doing:
1. We define a function called sayHello.
2. We call the setTimeout function, which takes two arguments:
– The first argument is the function we want to call after the delay.
– The second argument is the delay in miliseconds.
3. The setTimeout function returns a timerId, which we don’t need in this example.
4. The setTimeout function waits for the delay to expire, then calls the sayHello function.

Similar Posts