Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save jwalsh/39bf8294e5aff84803d0530f14da296b 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(post => {
console.log(`| ${users[post.userId].name} | ${users[post.userId].website} | ${post.title} |`);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment