Skip to content

Instantly share code, notes, and snippets.

@ivankisyov
Last active October 14, 2018 15:03
Show Gist options
  • Save ivankisyov/3d9be47e511bf2e24e720a859d60090b to your computer and use it in GitHub Desktop.
Save ivankisyov/3d9be47e511bf2e24e720a859d60090b to your computer and use it in GitHub Desktop.
Promises

Promises

Promise.all

node.js

const axios = require("axios");

const getCountriesByRegion = region => {
  return axios
    .get(`https://restcountries.eu/rest/v2/region/${region}`)
    .then(response => response.data.map(country => country.name));
};

const countriesInAsia = getCountriesByRegion("asia");
const countriesInEurope = getCountriesByRegion("europe");

Promise.all([countriesInAsia, countriesInEurope])
  .then(values => console.log(values))
  .catch(e => console.log(e));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment