handling text plain in express 3 via connect

handling text plain in express 3 via connect  using -'node.js,express,connect'

I am using Express 3, and would like to handle text/plain POSTs.

Express 3 uses connect's bodyParser now (I think the old Express code got moved to connect). The documentation for bodyParser gives some details about how to make it support additional file types. And I found an excellent blog post about how handling text/plain was done in old versions of Express).

Should I explicitly require connect (and let node's require cache the modified version)? Or is connect exposed via express somewhere?
connect.bodyParser does not have a 'parse' key.

How can I make Express (via connect) handle text/plain POSTs?

asked Sep 18, 2015 by sumit_jaiswalmca
0 votes

2 Answers

0 votes


app.use(function(req, res, next){
  if (req.is('text/*')) {
    req.text = '';
    req.on('data', function(chunk){ req.text += chunk });
    req.on('end', next);
  } else {

Will add the text as req.text

answered Sep 18, 2015 by ashishshukla
0 votes

I would just make a module similar to the json.js middleware module and just don't bother converting the buf data into anything else. Wrap it into a plain.js file, apply some decent "don't repeat yourself" refactoring, and submit a pull request to connect. Seems generally handy. However, note that while convenient, large enough request bodies will require streaming straight to disk at some point so you don't consume all the memory in your node server.

answered Sep 18, 2015 by shikhar jain