How to get rid of Connect 3.0 deprecation alert?

旧城冷巷雨未停 提交于 2019-11-27 17:39:51

This is a warning that will go away once Express updates to use Connect 3.0 - as a temporary fix, follow the instructions at the top of https://github.com/senchalabs/connect/wiki/Connect-3.0. Specifically, find this line in your app:

app.use(express.bodyParser());

And replace it with the following (this is what bodyParser will be in 3.0):

app.use(express.json());
app.use(express.urlencoded());
Jonathan Ong

i'm responsible for this deprecation notice. did you read the wiki? https://github.com/senchalabs/connect/wiki/Connect-3.0

step 1: use each parser directly instead of app.use(express.bodyParser());

app.use(express.json());
app.use(express.urlencoded());

step 2: use a different multipart parser, for e.g: connect-multiparty can be used

app.use(require('connect-multiparty')())

work on connect 3 and express 4 hasn't begun yet because node 0.12 is taking a while to be released. there's nothing to update, yet.

since express is just a wrapper to connect, i suggest using connect directly.

so instead of: app.use(express.bodyParser());

use:

connect = require('connect');
app.use(connect.json());
app.use(connect.urlencoded());
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!