亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

出現"Most middleware (like bodyParser) is no longer bundled with Express"錯誤怎么解決

命令行里選定指定路徑然后輸入 node app.js?

會提示:

Error: Most middleware (like bodyParser) is no longer bundled with Express and m

ust be installed separately. Please see https://github.com/senchalabs/connect#mi

ddleware.

? ? at Function.Object.defineProperty.get (E:\dcspace\node\imooc\node_modules\ex

press\lib\express.js:89:13)

? ? at Object.<anonymous> (E:\dcspace\node\imooc\app.js:8:17)

? ? at Module._compile (module.js:456:26)

? ? at Object.Module._extensions..js (module.js:474:10)

? ? at Module.load (module.js:356:32)

? ? at Function.Module._load (module.js:312:12)

? ? at Function.Module.runMain (module.js:497:10)

? ? at startup (node.js:119:16)

? ? at node.js:906:3


然后去他給的這個github上安裝了connect()中間件,為什么還是無法啟動,還是報這樣的錯呢

正在回答

4 回答

Returns middleware that only parses?urlencoded?bodies. This parser accepts only UTF-8 encoding of the body and supports automatic inflation of?gzip?and?deflate?encodings.

A new?body?object containing the parsed data is populated on the?request?object after the middleware (i.e.req.body). This object will contain key-value pairs, where the value can be a string or array (when?extended?isfalse), or any type (when?extended?is?true).

The?urlencoded?function takes an option?options?object that may contain any of the following keys:

The?extended?option allows to choose between parsing the URL-encoded data with the?querystring?library (when?false) or the?qs?library (when?true). The "extended" syntax allows for rich objects and arrays to be encoded into the URL-encoded format, allowing for a JSON-like experience with URL-encoded. For more information, pleasesee the qs library.


0 回復 有任何疑惑可以回復我~

bodyParser.urlencoded 中設置 extended 為 true 和為 false 有什么區別嗎?

0 回復 有任何疑惑可以回復我~
#1

根號三

求解.竟然沒法追加提問?╮(╯▽╰)╭
2015-04-28 回復 有任何疑惑可以回復我~
#2

夏不語冰 回復 根號三

可以把 右上角有只編輯筆
2017-08-21 回復 有任何疑惑可以回復我~
#3

蝴蝶是我_我就是蝴蝶

bodyParser 中間件,可以將post數據轉成js對象, 要求請求頭的content-type屬性是 application/x-www-form-urlencoded 或者application/json true或者false應該是這個區別
2018-11-06 回復 有任何疑惑可以回復我~
按照樓上大哥?說的倒是能跑通了,但是后面提交數據的時候需要將?extended:?false?改為
extended:?true
否則會報錯:
TypeError:?Cannot?read?property?'_id'?of?undefined

相關資料:
通常?POST?內容的格式是?application/x-www-form-urlencoded,?因此要用下面的方式來使用:
app.use(require('body-parser').urlencoded({extended:?true}))
見:
https://github.com/expressjs/body-parser


2 回復 有任何疑惑可以回復我~

首先翻譯這句英文,大概的意思就是新版的express中已經不包含bodyparser了,那就需要大家單獨安裝bodyparser,安裝命令是npm install body-parser,然后在app.js中加載body-parser模塊var bodyParser = require('body-parser'),把app.use(express.bodyParser())替換成app.use(bodyParser.urlencoded({ extended: false })),這樣調試就沒問題了。

12 回復 有任何疑惑可以回復我~
#1

stono

老師好! 按著老師說的改了,的確過了;
2015-01-28 回復 有任何疑惑可以回復我~
#2

James_dai

恩,確實有用!
2016-11-24 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
node+mongodb 建站攻略(一期)
  • 參與學習       91827    人
  • 解答問題       921    個

帶你完整實現一個從前端到后端的項目,初中級前端開發工程師必學課程

進入課程

出現"Most middleware (like bodyParser) is no longer bundled with Express"錯誤怎么解決

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號