nodejs methods using async await examples

Example 1: async await

const data = async ()  => {
  const got = await fetch('https://jsonplaceholder.typicode.com/todos/1');
  
  console.log(await got.json())
}

data();

Example 2: async await

async function showAvatar() {
	// read
  	await setTimeout(resolve, 3000);
    // read next 3s
}

showAvatar();

Example 3: async await

async function () {
  const fetchAPI = fetch(`https://bn-hadith-api.herokuapp.com/hadiths/0`);
  const response = await fetchAPI;
  const data = await response.json();
  console.log(data);
}

Tags:

Misc Example