身体解析器做什么与快递? [英] What does body-parser do with express?
问题描述
我不明白为什么我们需要在Express应用程序中使用 body-parser
,因为我们可以在不使用 body-parser
。
它实际上是做什么和如何?
I don't understand why we need body-parser
in an Express application, as we can get data without using body-parser
.
And what does it do actually and how?
推荐答案
在Express.js版本4中处理HTTP POST请求,以上,您需要安装称为body-parser的中间件模块。
To handle HTTP POST request in Express.js version 4 and above, you need to install middleware module called body-parser.
body-parser提取传入的请求流的整个身体部分,并将其暴露在req.body上。
body-parser extract the entire body portion of an incoming request stream and exposes it on req.body .
中间件早期是Express.js的一部分,但现在您必须单独安装。
The middleware was a part of Express.js earlier but now you have to install it separately.
身体解析器模块解析使用HTTP POST请求提交的JSON,缓冲区,字符串和URL编码数据。使用NPM安装身体解析器,如下所示。
This body-parser module parses the JSON, buffer, string and url encoded data submitted using HTTP POST request. Install body-parser using NPM as shown below.
npm install body-parser --save
这篇关于身体解析器做什么与快递?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!