From b986540e05c26184337b8f042adc89f4687a299d Mon Sep 17 00:00:00 2001 From: vuongducdai Date: Thu, 4 Aug 2022 15:42:32 +0700 Subject: [PATCH] Update main.js --- 18_Day_Promises/18_day_starter/scripts/main.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/18_Day_Promises/18_day_starter/scripts/main.js b/18_Day_Promises/18_day_starter/scripts/main.js index c6045c8..0f4a57e 100644 --- a/18_Day_Promises/18_day_starter/scripts/main.js +++ b/18_Day_Promises/18_day_starter/scripts/main.js @@ -1,2 +1,10 @@ -console.log(countries) -alert('Open the console and check if the countries has been loaded') \ No newline at end of file +import fetch from "node-fetch"; + +const url = 'https://restcountries.com/v2/all' // countries api +fetch(url) + .then(response => response.json()) // accessing the API data as JSON + .then(data => { + // getting the data + console.log(data) + }) + .catch(error => console.error(error)) // handling error if something wrong happens \ No newline at end of file