bodyParser is a middleware that analyzes json data stream. I see no reason not to use bodyParser (unless you want to handle multi-part bodies), but you can analyze the threads yourself if you want. It will be something like middleware below:
app.use(function( req, res, next ) {
var data = '';
req.on( 'data', function( chunk ) {
data += chunk;
});
req.on( 'end', function() {
req.rawBody = data;
console.log( 'on end: ', data )
if ( data && data.indexOf( '{' ) > -1 ) {
req.body = JSON.parse( data );
}
next();
});
});
If you want to parse multi-part bodies, you can use one of the following modules:
- busboy
- multi-party
- fine
- multer
source
share