简体   繁体   中英

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. For example:

body-parser - Parse HTTP request body. Replaces built-in function 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 :

This is a built-in middleware function in Express. It parses incoming requests with JSON payloads and is based on body-parser.

...

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.

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 . Now each module is independent but still included as a dependency in the package.json of express.js .

It is somewhat confusing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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