Published
- 1 min read
node sleep
The solution for this is noted below
node sleep
Solution
// one liner
await new Promise((resolve) => setTimeout(resolve, 5000))
// or re-usable `sleep` function:
async function init() {
console.log(1)
await sleep(1000)
console.log(2)
}
function sleep(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms)
})
}
Try other methods by searching on the site. That is if this doesn’t work