import fetch from 'node-fetch'; fetch('https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY') .then((response) => response.json()) .then((data) => console.log(data));
const axios = require('axios'); (async () => { try { const response = await axios.get( 'https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY' ); console.log(response.data.url); console.log(response.data.explanation); } catch (error) { console.log(error.response.body); } })();
import https from 'https'; async function get_page(substr) { const url = `https://jsonmock.hackerrank.com/api/movies/search/?Title=${substr}`; return new Promise((resolve) => { https.get(url, (res) => { let data = ''; res.on('data', (chunk) => { data += chunk; }); res.on('end', () => { resolve(console.log(data)); }); }); }); } // usage (async () => await get_page('spiderman'))();