bodyParser

lib/middleware/bodyParser.js

Parse request bodies.

By default application/json, application/x-www-form-urlencoded, and multipart/form-data are supported, however you may map connect.bodyParser.parse[contentType] to a function receiving (req, options, callback).

Examples

 connect.createServer(
     connect.bodyParser()
   , function(req, res) {
     res.end('viewing user ' + req.body.user.name);
   }
 );

 $ curl -d 'user[name]=tj' http://localhost/
 $ curl -d '{"user":{"name":"tj"}}' -H "Content-Type: application/json" http://localhost/

Multipart req.files:

As a security measure files are stored in a separate object, stored as req.files. This prevents attacks that may potentially alter filenames, and depending on the application gain access to restricted files.

Multipart configuration

The options passed are provided to each parser function. The multipart/form-data parser merges these with formidable's IncomingForm object, allowing you to tweak the upload directory, size limits, etc. For example you may wish to retain the file extension ## and change the upload directory

 server.use(bodyParser({ uploadDir: '/www/mysite.com/uploads' }));

View node-formidable for more information.

If you wish to use formidable directly within your app, and do not desire this behaviour for multipart requests simply remove the ## parser

delete connect.bodyParser.parse['multipart/form-data'];

Or

delete express.bodyParser.parse['multipart/form-data'];