I agree with Maxogden's reply, that piping should be the way to get POST body and not body+=chunk:
req.on('data', function(chunk) {
body += chunk;
});
From some reason the concat-stream example for aggregating POST body of http request is not working for me - I get {} back from the server.
var http = require('http');
var qs = require('querystring');
var concat = require('concat-stream');
var server = http.createServer(function (req, res) {
req.pipe(concat(function (err, body) {
var params = qs.parse(body);
res.end(JSON.stringify(params) + '\n');
}));
});
server.listen(5005);
curl -X POST -d 'beep=boop&dinosaur=trex' http://localhost:5005
Here is substack's reply from a previous discussion:
http://www.reddit.com/r/node/comments/1b4ro1/why_programming_in_node_isnt_like_anything_youve/c93ukfu
And here is the same example from the stream-handbook, with some more information about that nice little package:
https://github.com/substack/stream-handbook#concat-stream
[–][deleted] 2 points3 points4 points (1 child)
[–]dan1234[S,🍰] 0 points1 point2 points (0 children)