连接中间件中的bodyParser()是做什么的?

我正在做一个关于node.js的教程,这个教程告诉我如何使用节点创build一个服务器。 在下面的代码中,connect.bodyParser()行是干什么用的?

var app = connect() .use(connect.bodyParser()) .use(connect.static('public')) .use(function (req, res) { if (req.url === '/process') { res.end(req.body.name + ' would repeat ' + req.body.repeat + ' times.'); } else { res.end("Invalid Request"); } }) .listen(3000); 

它用(除其他外) POST参数的值填充req.body 。 以下是文档和示例: http : //expressjs.com/api.html#req.body

bodyParser是“连接”的一部分,它是node.js的一组中间件。 以下是来自Connect的真实文档和来源: http : //www.senchalabs.org/connect/bodyParser.html

正如你所看到的,这只是一个简单的包装,试图解码JSON,如果失败尝试决定URLEncoded,如果失败尝试解码多部分。