Skip to content

Instantly share code, notes, and snippets.

@oze4
Created September 27, 2019 23:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oze4/698881cbd0141c66fc7817eeb95dd1b7 to your computer and use it in GitHub Desktop.
Save oze4/698881cbd0141c66fc7817eeb95dd1b7 to your computer and use it in GitHub Desktop.
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