Asynchronous JS with a async/await

node v8.17.0
version: master
endpointsharetweet
// Lesson 02: https://egghead.io/lessons/javascript-call-an-asynchronous-function-in-a-promise-chain const fetch = require("node-fetch") async function showGitHubUser(handle) { const url = `https://api.github.com/users/${handle}`; const response = await fetch(url); return await response.json(); } showGitHubUser("omar12") .then(user => { console.log('Lesson 2'); console.log(user.name); console.log(user.location); });
// Lesson 03: https://egghead.io/lessons/javascript-convert-any-function-into-an-asynchronous-function class GitHubApiClient { async fetchUser(handle) { const url = `https://api.github.com/users/${handle}`; const response = await fetch(url); return await response.json(); } } (async () => { const client = new GitHubApiClient(); const user = await client.fetchUser("omar12"); console.log('Lesson 3'); console.log(user.name); console.log(user.location); })();
Loading…

no comments

    sign in to comment