Skip to content

Instantly share code, notes, and snippets.

@jwalsh
Created July 20, 2017 21:28
Show Gist options
  • Select an option

  • Save jwalsh/eb183992e5992491082f854dd476ccef to your computer and use it in GitHub Desktop.

Select an option

Save jwalsh/eb183992e5992491082f854dd476ccef to your computer and use it in GitHub Desktop.
const fetch = require('node-fetch');
let posts = [];
let postsPromise = fetch('https://jsonplaceholder.typicode.com/posts')
.then(resp => resp.json())
.then(data => {
posts = data.slice(5,15);
});
let users = {};
let usersPromise = fetch('https://jsonplaceholder.typicode.com/users')
.then(resp => resp.json())
.then(data => {
users = data.reduce((p, c) => {
p[c.id] = c;
return p;
}, {});
});
Promise
.all([postsPromise, usersPromise])
.then(responses => {
// console.log(posts, users);
let table = posts.map(e => {
return {
author: users[e.userId].name,
website: users[e.userId].website,
title: e.title
};
});
console.log(table);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment