By default, express does not buffer data unless you add middleware for this. A simple solution is to follow the example in @Stewe's answer below, which will simply concatenate all the data yourself. eg.
var concat = require('concat-stream'); app.use(function(req, res, next){ req.pipe(concat(function(data){ req.body = data; next(); })); });
The disadvantage of this is that you have now moved all the contents of the POST body to RAM as a continuous fragment, which may not be needed. Another option that is worth considering, but depends on how much data you need to process in the body of the message, will process the data as a stream instead.
For example, with XML, you can use an XML parser that supports XML parsing because it comes in fragments. One such parser will be an XML stream . You are doing something like this:
var XmlStream = require('xml-stream'); app.post('/', function(req, res) { req.setEncoding('utf8'); var xml = new XmlStream(req); xml.on('updateElement: sometag', function(element) {
loganfsmyth Mar 29 '12 at 18:43 2012-03-29 18:43
source share