Clone and edit this document
Runkit
Runkit
home page
user forum
new notebook
clone notebook
download notebook
support & documentation
log in
sign up
new notebook
help & feedback
clone this notebook
download this notebook
Sign In
Sign Up
async/await Example
node v6.17.1
version:
1.2.2
endpoint
share
tweet
Compares purely Promise-based approach to async/await approach.
Import fetch
const fetch = require("node-fetch");
Promised-based Request
const requestAnimePromise = id => { fetch(`https://jikan.me/api/anime/${id}`) .then(response => response.json()) .then(json => { console.log("Promise-based") console.log(json) }); } requestAnimePromise(1);
async/await based Request
const requestAnimeAwait = async (id=100) => { const response = await fetch(`https://jikan.me/api/anime/${id}`) const json = await response.json(); console.log("async/await based"); console.log(json); } requestAnimeAwait();
Loading…
no comments
sign in
to comment