Node.js Sleep using Async/Await

Are you also downloading lots of data from an API and need a simple way to throttle? Here is a quick snippet on how to use sleep (a function common in many languages).

function sleep(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}

async function work() {
  console.log('Start sleeping');
  await sleep(5000);
  console.log('Five seconds later');
}

work();