/* * Setup for Node environment * - Execute "npm install node-fetch" to install fetch API library * - Import fetch using "const fetch = require('node-fetch')" */ const fetch = require("node-fetch"); // What does "https://api.github.com/users" return? - Try visiting from browser async function main() { let promise = fetch("https://api.github.com/users"); console.log(promise); // let res = await promise; // returns Response object // console.log(res); // Check if response was successful - status codes in [200, 299] // console.log(res.ok); // let data = await res.json(); // json() method as well returns a promsie // console.log(data); // console.log(data[0]); // console.log(data[0].login); } main(); // Using .then().catch() // fetch(`https://api.github.com/users`) // .then((res) => res.json()) // .then((data) => console.log(data)) // .catch((error) => console.log(error));