码迷,mamicode.com
首页 > 移动开发 > 详细

nodejs 使用app.use(express.bodyParser()); 出行异常----解决方法

时间:2015-01-07 15:04:16      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:

异常代码:

\Workspaces\WebStormProject\imooc-project\imooc>node app.js

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.Object.defineProperty.get (L:\Workspaces\WebStormProject\imooc-project\imooc\node_modules\express\lib\express.js:89:13)
    at Object.<anonymous> (L:\Workspaces\WebStormProject\imooc-project\imooc\app.js:12: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:902:3
    当前express版本:3.5.3

根据错误可以知道bodyparser已经不和 Express绑定在一起了,说明当前express不包含body-parser,执行如下命令即可:npm install body-parser

解决:

var app = require('express')();
var bodyParser = require('body-parser');
var multer = require('multer'); 

app.use(bodyParser.json()); // for parsing application/json
app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
app.use(multer()); // for parsing multipart/form-data

app.post('/', function (req, res) {

  console.log(req.body);
  res.json(req.body);

})

nodejs 使用app.use(express.bodyParser()); 出行异常----解决方法

标签:

原文地址:http://blog.csdn.net/huangjihua0402/article/details/42491077

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!