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
Post a Comment