Created
June 5, 2019 20:45
-
-
Save fijimunkii/8388b03f9a141968d95a03584a67fa8e to your computer and use it in GitHub Desktop.
node get multiple https urls and join result
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 https = require('https'); | |
const urls = ['https://postman-echo.com/get','https://httpbin.org/anything']; | |
Promise.all(urls.map(url => new Promise((resolve,reject) => { | |
https.get(url, r => { | |
const data = []; | |
r.on('data', d => data.push(d)); | |
r.on('end', () => resolve(Buffer.concat(data).toString())); | |
}).on('error',console.log); | |
}))) | |
.then(d => console.log(d.join('')), console.log); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment