node.js - Why nodejs return chunked data in request? -


when make http request, need concatenate response:

request.on('response', function (response) { var body = ''; response.on('data', function (chunk) {     body += chunk;     }); ... 

why implemented way? why not output whole result?

what you're getting stream, handy construct in node.js. required reading: https://github.com/substack/stream-handbook

if want wait until you've received whole response, can easily:

var concat = require('concat-stream');  request.on('response', function(response) {     response.pipe(concat(function(body) {         console.log(body);     })); }); 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -