MySQL 错误:大多数中间件(如 json)不再与 Express 捆绑在一起,必须单独安装。请参见

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23033473/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 20:25:30  来源:igfitidea点击:

Error: Most middleware (like json) is no longer bundled with Express and must be installed separately. Please see

mysqljsonnode.jsexpress

提问by incleaf

i move my source window to ubuntu :

我将我的源窗口移动到 ubuntu :

Error: Most middleware (like json) is no longer bundled with Express and must be installed separately. Please see https://github.com/senchalabs/connect#middleware.

错误:大多数中间件(如 json)不再与 Express 捆绑在一起,必须单独安装。请参阅https://github.com/senchalabs/connect#middleware

this is my source thank you

这是我的来源谢谢

var http = require('http');
var fs = require('fs');
var express = require('express');
var mysql = require('mysql');
var ejs = require('ejs');

var app = express();
app.use(express.bodyParser());
app.use(app.router);

回答by kmchugh12

There are a number of changes with express 4.x. Like the error says, all of the middleware has been removed.

express 4.x 有很多变化。就像错误所说的那样,所有中间件都已被删除。

Update your package.json to include the "new" packages, a basic list can be found hereand a full list here

更新你的 package.json 以包含“新”包,基本列表可以在这里找到,完整列表可以在这里找到

Using your code from above, you would just need the following:

使用上面的代码,您只需要以下内容:

// package.json
{
  "dependencies":
  {
    "express":"*",
    "body-parser":"*"
  }
}

Then update your source to reflect the new changes:

然后更新您的源以反映新的更改:

// app.js
var http = require('http'),
    fs = require('fs'),
    express = require('express'),
    bodyParser = require('body-parser'),
    mysql = require('mysql'),
    ejs = require('ejs');

var app = express();
app.use(bodyParser.urlencoded({
    extended: true
}));
app.use(bodyParser.json());

Note that app.use(app.router) has been removed as well.

请注意, app.use(app.router) 也已被删除。

回答by Partha Roy

if some middleware is not bundled with express then dont use express keyword while using them..

如果某些中间件没有与 express 捆绑在一起,那么在使用它们时不要使用 express 关键字..

instead of this -

而不是这个 -

app.use(express.bodyParser());

write this -

写这个——

app.use(bodyParser());

回答by Zaryab baloch

In my case i was exporting a package that i didn't install i.e express package. after installing the package my issue went away. the middleware i was using is

就我而言,我正在导出一个我没有安装的包,即快递包。安装软件包后,我的问题就消失了。我使用的中间件是

app.use(express.json())

Check your package.json file whether you installed the package or not. If it is not installed then you might be getting same error.

检查您的 package.json 文件是否安装了该软件包。如果未安装,则您可能会遇到相同的错误。