Created
July 20, 2017 21:33
-
-
Save jwalsh/39bf8294e5aff84803d0530f14da296b to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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