const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));Usage
async function demo() {
console.log('Start');
await sleep(2000);
console.log('After 2 seconds');
}
demo();const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));async function demo() {
console.log('Start');
await sleep(2000);
console.log('After 2 seconds');
}
demo();This page is open source. Noticed a typo? Or something unclear?
Improve this page on GitHub

Written byTarun Sharma Follow @tkssharma
Full-stack developer and tech educator with 10+ years of experience building scalable applications. Passionate about Node.js, NestJS, React, and cloud technologies. Creator of 50+ courses on Udemy and active YouTube educator helping developers level up their skills.
Connect
Stack Overflow Clone - APIs Integration Redux Toolkit [Closure] - App Demo #05
Become Ninja Developer - API security Best Practices with Node JS Packages #15
Nest JS Microservices using HTTP Gateway and Redis Services (DEMO) #nestjs #microservices #16