Skip to content

Instantly share code, notes, and snippets.

@clicktechnology
Last active November 8, 2021 21:08
Show Gist options
  • Save clicktechnology/740b77492f2c027ac2a2a766bc93f812 to your computer and use it in GitHub Desktop.
Save clicktechnology/740b77492f2c027ac2a2a766bc93f812 to your computer and use it in GitHub Desktop.
JavaScript / NodeJS - Fetch using Async / await
const fetchPokemon = async (id) => {
try {
const res = await fetch(`https://pokeapi.co/api/v2/pokemon/${id}`);
const data = await res.json()
console.log('LOL', data, data.name)
console.log(res.status) // get the html code too, check for 200 or 404/500 etc.
} catch(err) {
console.error(err)
} finally {
console.log('I will always run no matter what.')
}
}
fetchPokemon(2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment