Error: Most middleware (like bodyParser) is no longer bundled with ExpressJs

Error: Most middleware (like bodyParser) is no longer bundled with ExpressJs

我在尝试 运行 我的应用程序时不断收到上述错误,无法弄清楚我没有添加什么包..

服务器在添加此文档之前运行良好,所以我希望这是此文档的问题,而不是其他问题。

它是一个名为 node-scheduler 的 npm

var express = require('express');
var router = express.Router()
var path = require('path');
var bodyParser = require('body-parser');

var db = require('mongoskin').db("localhost/awl-loan-system", { w: 0});
db.bind('event');


var app = express();
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.bodyParser());


app.get('/init', function(req, res){
db.event.insert({ 
    text:"My test event A", 
    start_date: new Date(2013,8,1),
    end_date:   new Date(2013,8,5)
});
db.event.insert({ 
    text:"My test event B", 
    start_date: new Date(2013,8,19),
    end_date:   new Date(2013,8,24)
});
db.event.insert({ 
    text:"Morning event", 
    start_date: new Date(2013,8,4,4,0),
    end_date:   new Date(2013,8,4,14,0)
});
db.event.insert({ 
    text:"One more test event", 
    start_date: new Date(2013,8,3),
    end_date:   new Date(2013,8,8),
    color: "#DD8616"
});

res.send("Test events were added to the database")
});


app.get('/data', function(req, res){
db.event.find().toArray(function(err, data){
    //set id property for all records
    for (var i = 0; i < data.length; i++)
        data[i].id = data[i]._id;

    //output response
    res.send(data);
});
});


app.post('/data', function(req, res){
var data = req.body;
var mode = data["!nativeeditor_status"];
var sid = data.id;
var tid = sid;

delete data.id;
delete data.gr_id;
delete data["!nativeeditor_status"];


function update_response(err, result){
    if (err)
        mode = "error";
    else if (mode == "inserted")
        tid = data._id;

    res.setHeader("Content-Type","text/xml");
    res.send("<data><action type='"+mode+"' sid='"+sid+"' tid='"+tid+"'/>
</data>");
}

if (mode == "updated")
    db.event.updateById( sid, data, update_response);
else if (mode == "inserted")
    db.event.insert(data, update_response);
else if (mode == `enter code here`"deleted")
    db.event.removeById( sid, update_response);
else
    res.send("Not supported operation");
});

返回此错误

D:\One31\Clients\A W Lymn\node_modules\express\lib\express.js:107
  throw new Error('Most middleware (like ' + name + ') is no longer bundled 
with Express and must be installed separately. Please see 
https://github.com/senchalabs/connect#middleware.');
       ^

Error: Most middleware (like bodyParser) is no longer bundled with Express 
and must be installed separately. Please see 
https://github.com/senchalabs/connect#middleware.
 at Function.get (D:\One31\Clients\A W 
Lymn\node_modules\express\lib\express.js:107:13)
 at Object.<anonymous> (D:\One31\Clients\A W Lymn\routes\calendar.js:12:16)
 at Module._compile (module.js:570:32)
 at Object.Module._extensions..js (module.js:579:10)
 at Module.load (module.js:487:32)
 at tryModuleLoad (module.js:446:12)
 at Function.Module._load (module.js:438:3)
 at Module.require (module.js:497:17)
 at require (internal/module.js:20:19)
 at Object.<anonymous> (D:\One31\Clients\A W Lymn\routes\index.js:6:16)
 at Module._compile (module.js:570:32)
 at Object.Module._extensions..js (module.js:579:10)
 at Module.load (module.js:487:32)
 at tryModuleLoad (module.js:446:12)
 at Function.Module._load (module.js:438:3)
 at Module.require (module.js:497:17)

有什么帮助吗?

需要通过运行

单独安装body-parser

npm i body-parser -S

-S 标志将包添加到您的 package.json 文件

您已经包含单独的 body-parser 模块,因此请使用 bodyParser.urlencoded({ extended: false })/bodyParser.json() 而不是 express.bodyParser()