简体   繁体   English

中间件取代内置的Express.js功能有什么意义?

[英]What's the point of middlewares replacing built in Express.js functions?

There's quite a list of Express.js middlewares replacing built-in functions. 一个Express.js中间件列表取代了内置函数。 For example: 例如:

body-parser - Parse HTTP request body. body-parser - 解析HTTP请求体。 Replaces built-in function express.bodyParser 替换内置函数express.bodyParser

What do they mean when they say "replaces built-in function"? 当他们说“取代内置功能”时,他们的意思是什么? Do those replacements provide any improvement on top of built-in versions? 这些替换件是否在内置版本之上提供了任何改进? I mean I do not see any point in using additional modules, if they don't. 我的意思是我没有看到使用其他模块的任何意义,如果他们不这样做。 I'm asking 'cause I do not see it mentioned anywhere, at least in the middleware documentation. 我问'因为我没有在任何地方看到它,至少在中间件文档中。

It means that it overrides default behavior or object natively given in the app. 这意味着它会覆盖应用程序中本机给出的默认行为或对象。

Excerpt from the doc, for example the res.json : 摘自doc,例如res.json

This is a built-in middleware function in Express. 这是Express中的内置中间件功能。 It parses incoming requests with JSON payloads and is based on body-parser. 它使用JSON有效负载解析传入的请求,并基于正文解析器。

... ...

A new body object containing the parsed data is populated on the request object after the middleware (ie req.body ), or an empty object ({}) if there was no body to parse, the Content-Type was not matched, or an error occurred. 在中间件(即req.body )之后的请求对象上填充一个包含已解析数据的新body对象,如果没有要解析的主体,Content-Type未匹配,则填充空对象({})发生了错误。

The body-parser in question is useful for me, I used it to recover the data transmitted in an post form for example. 有问题的正文解析器对我很有用,我用它来恢复以帖子形式传输的数据。

Since the update to express v4 original builtin functions were separated into standalone modules . 由于表达v4原始内置函数的更新被分成独立模块 Now each module is independent but still included as a dependency in the package.json of express.js . 现在每个模块都是独立的,但仍然作为依赖包含在express.jspackage.json中

It is somewhat confusing. 这有点令人困惑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM