Quantcast
Channel: Where is the body in a nodejs http.get response? - Stack Overflow
Viewing all articles
Browse latest Browse all 24

Answer by Uriel for Where is the body in a nodejs http.get response?

$
0
0

Just an improved version to nkron responce.

const httpGet = url => {  return new Promise((resolve, reject) => {    http.get(url, res => {      res.setEncoding('utf8');      const body = [];      res.on('data', chunk => body.push(chunk));      res.on('end', () => resolve(body.join('')));    }).on('error', reject);  });};

Appending chunks in an string[] is better for memory usage, the join(''), will allocatenew memory only once.


Viewing all articles
Browse latest Browse all 24

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>