Error: Most middleware (like bodyParser) ...
运行NodeJS时出现如下错误:Error: Most middleware (like bodyParser) is no longer bundled with Express and must be installed separately. 意思是命令行中运行 npm install body-parser 回车,进行安装。对源代码进行调整,加上 var bodyParse
运行NodeJS时出现如下错误:
Error: Most middleware (like bodyParser) is no longer bundled with Express and must be installed separately.
意思是
命令行中运行 npm install body-parser
回车,进行安装。
对源代码进行调整,加上 var bodyParser = require('body-parser');
这一句,在调用的时候通过 bodeParser()
来调用就好了。
注意:不管是 install
还是 require
,都要注意是 body-parser
而不是 bodyParser
。
如果无法解决,请看:
https://github.com/expressjs/body-parser 。
里面有具体的body-parser用法,需要按照如下格式书写:
将:app.use(express.bodyParser()) 改写为下面样式
var express = require('express') var bodyParser = require('body-parser') var app = express() // parse application/x-www-form-urlencoded
app.use(bodyParser());
app.use(bodyParser.json({ type: 'application/vnd.api+json' })) app.use(bodyParser.urlencoded({ extended: false })) // parse application/json app.use(bodyParser.json()) // parse application/vnd.api+json as json app.use(bodyParser.json({ type: 'application/vnd.api+json' })) app.use(function (req, res, next) { console.log(req.body) // populated! next() })
Tips:
1. Body Parser Problem.
Error Message>
Most middleware (like bodyParser) is no longer bundled with Express and must be installed separately. Please see https://github.com/senchalabs/connect#middleware.
Error: Cannot find module 'body-parser'
Solution>
>npm info body-parser version
npm http GET https://registry.npmjs.org/body-parsernpm http 200 https://registry.npmjs.org/body-parser1.2.0
开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!
更多推荐
所有评论(0)