Skip to content

Instantly share code, notes, and snippets.

@Californ1a
Created April 11, 2018 17:20
Show Gist options
  • Save Californ1a/780528657cb46a4c4a33b7e93707d9ea to your computer and use it in GitHub Desktop.
Save Californ1a/780528657cb46a4c4a33b7e93707d9ea to your computer and use it in GitHub Desktop.
merge data from multiple fetch request
const fetch = require("node-fetch");
const urls = ["http://35.185.40.23/", "http://distance.rip:23469/"];
Promise.all(urls.map(fetch))
.then(responses => Promise.all(responses.map(res => res.json())))
.then(multiData => multiData.reduce((merge, data) => ({
...merge,
...data
}), {}))
.then(merged => {
console.log(JSON.stringify(merged, null, 2));
//whatever you're doing with the data here
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment