javascript 如何摆脱 Connect 3.0 弃用警报?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19581146/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get rid of Connect 3.0 deprecation alert?
提问by Alevardi
I'm a node.js developer who creates web apps using express.js. By now, my problem is:
我是一名 node.js 开发人员,他使用 express.js 创建 Web 应用程序。到目前为止,我的问题是:
Whenever I create an app on my computer, npm install its stuff and run it (with node app.js and nodemon) I get this message in the console:
每当我在我的计算机上创建一个应用程序时,npm 安装它的东西并运行它(使用 node app.js 和 nodemon)我在控制台中收到以下消息:
connect.multipart() will be removed in connect 3.0
visit https://github.com/senchalabs/connect/wiki/Connect-3.0 for alternatives
connect.limit() will be removed in connect 3.0
Express server listening on port 3000
The app works, that's fine. But when I clone an app created in other computer I don't get that message, so I'm supposing I have something outdated in my computer.
该应用程序有效,这很好。但是当我克隆在其他计算机上创建的应用程序时,我没有收到该消息,所以我假设我的计算机中有一些过时的东西。
I went to the site mentioned in the message and confirmed my speculations. That is a deprecation warning. However, I've updated node and npm and globally express but I still getting the note.
我去了消息中提到的网站,证实了我的猜测。这是一个弃用警告。但是,我已经更新了 node 和 npm 以及 global express,但我仍然收到了注释。
My problem is, therefore: I don't know what do I need to update in order to get rid of the deprecation notes because they're freaking me out.
因此,我的问题是:我不知道我需要更新什么才能摆脱弃用注释,因为它们让我感到害怕。
I hope someone can help me. Thanks a lot.
我希望有一个人可以帮助我。非常感谢。
回答by Jacob Gillespie
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:
这是一个警告,一旦 Express 更新为使用 Connect 3.0,该警告就会消失 - 作为临时修复,请按照https://github.com/senchalabs/connect/wiki/Connect-3.0顶部的说明进行操作。具体来说,在您的应用中找到这一行:
app.use(express.bodyParser());
And replace it with the following (this is what bodyParser
will be in 3.0):
并将其替换为以下内容(这是bodyParser
3.0 中的内容):
app.use(express.json());
app.use(express.urlencoded());
回答by Jonathan Ong
i'm responsible for this deprecation notice. did you read the wiki? https://github.com/senchalabs/connect/wiki/Connect-3.0
我负责此弃用通知。你读过维基吗?https://github.com/senchalabs/connect/wiki/Connect-3.0
step 1: use each parser directly instead of app.use(express.bodyParser());
第 1 步:直接使用每个解析器而不是 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
第 2 步:使用不同的多部分解析器,例如:可以使用 connect-multiparty
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.
连接 3 和 express 4 的工作尚未开始,因为节点 0.12 需要一段时间才能发布。还没有什么要更新的。
回答by Sagiv Ofek
since express is just a wrapper to connect, i suggest using connect directly.
由于 express 只是连接的包装器,我建议直接使用 connect。
so instead of:
app.use(express.bodyParser());
所以而不是:
app.use(express.bodyParser());
use:
利用:
connect = require('connect');
app.use(connect.json());
app.use(connect.urlencoded());