Created
September 27, 2019 23:54
-
-
Save oze4/698881cbd0141c66fc7817eeb95dd1b7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const request = require('request'); | |
let MY_THINGS = []; | |
function getItems() { | |
let url = 'https://jsonplaceholder.typicode.com/todos/'; | |
return new Promise((resolve, reject) => { | |
request.get(url, (err, res, body) => { | |
if(err) reject(err); | |
if(res.statusCode !== 200) reject(res.statusCode); | |
let theItems = JSON.parse(body).map(i => { return i.title }); | |
resolve(theItems); | |
}) | |
}) | |
} | |
module.exports = async function doGetItems() { | |
let things = await getItems(); | |
things.forEach(thing => MY_THINGS.push(thing)); | |
console.log(MY_THINGS); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment