express.json与bodyParser.json [英] express.json vs bodyParser.json

查看:184
本文介绍了express.json与bodyParser.json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个相对较新的应用程序,并且想知道应该使用哪个应用程序

I'm writing a relatively new app and was wondering which I should use:

express.json()

bodyParser.json()

我可以假设他们做同样的事情.

Can I assume they do the same thing.

我想只使用express.json(),因为它已经内置.

I would like to just use express.json() as it is built in already.

推荐答案

Express的早期版本曾经捆绑了很多中间件. bodyParser是随之而来的中间件之一.当Express 4.0发布时,他们决定从Express中删除捆绑的中间件,而是将它们变成单独的程序包.然后,在安装bodyParser模块之后,语法从app.use(express.json())更改为app.use(bodyParser.json()).

Earlier versions of Express used to have a lot of middleware bundled with it. bodyParser was one of the middlewares that came it. When Express 4.0 was released they decided to remove the bundled middleware from Express and make them separate packages instead. The syntax then changed from app.use(express.json()) to app.use(bodyParser.json()) after installing the bodyParser module.

bodyParser在4.16.0版中重新添加到Express中,因为人们希望它像以前一样与Express捆绑在一起.这意味着如果您使用的是最新版本,则不必再使用bodyParser.json().您可以改用express.json().

bodyParser was added back to Express in release 4.16.0, because people wanted it bundled with Express like before. That means you don't have to use bodyParser.json() anymore if you are on the latest release. You can use express.json() instead.

4.16.0的发行历史记录是此处感兴趣的人,以及拉取请求此处.

The release history is for 4.16.0 is here for those who are interested, and the pull request here.

这篇关于express.json与bodyParser.json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆