mysql - 错误 : Most middleware (like json) is no lon

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

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

这是我的来源,谢谢

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);

最佳答案

express 4.x 有许多变化。正如错误所说,所有中间件都已被删除。

更新您的 package.json 以包含"new"包,可以找到一个基本列表 here和完整列表 here

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

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

然后更新您的来源以反射(reflect)新的变化:

// 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());

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

关于mysql - 错误 : Most middleware (like json) is no longer bundled with Express and must be installed separately. 请参阅,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23033473/

相关文章:

json - 返回 Mvc.JsonResult 加上设置 Response.StatusCode

php - 在 Laravel 4 中将 Eloquent 模型返回为 JSON

json - 对于 Restful API,GET 方法可以使用 json 数据吗?

python - 用 json 编码元组的最佳方法

json - Jackson json反序列化,忽略json中的根元素

ruby-on-rails - 什么是 JSON 八位组,为什么需要两个?

json - 如何解析嵌套 JSON 对象中的内部字段

c# - 无法将当前 JSON 对象(例如 {"name":"value"})反序列化为类型 'Sy

json - 在 JSON 中禁用超文本应用程序语言 (HAL)?

json - 使用 d3.json 导入本地 json 文件不起作用