express抛出错误,因为“ body解析器不赞成使用undefined扩展”
在我的节点应用程序中,我正在使用Express。一切正常,但是我在遇到错误cmd
。我用的都是更新的模块…
var express = require('express');var bodyParser = require('body-parser');
var jade = require('jade');
var app = express();
app.set('view engine', 'jade');
app.set('views', __dirname + '/views');
app.use(express.static(__dirname + '/public'));
app.use(bodyParser.json()); // to support JSON-encoded bodies
app.use(bodyParser.urlencoded()); // to support URL-encoded bodies
app.get('/',function(req,res){
res.render('index.jade');
});
app.get('/login',function(req,res){
res.render('index.jade');
});
app.post('/login',function(req,res){
console.log(req.body);
});
app.get('/signup',function(req,res){
res.render('signup.jade');
});
var env = process.env.PORT || 3000;
app.listen(env, function(req, res){
console.log('i am working!');
});
D:\myLogin>node appbody-parser deprecated undefined extended: provide extended option app.js:11:20 //why i am getting this?
i am working!
{ username: 'jbarif@gmail.com', password: 'pass' } // i am getting response
有什么可以帮助我理解这个问题的吗?
回答:
您必须明确设置extended
为,bodyParser.urlencoded()
因为默认值将在的下一个主要版本中更改body-
parser。例:
app.use(bodyParser.urlencoded({ extended: true }));
从express
4.16.0开始,您还可以执行以下操作:
app.use(express.urlencoded({ extended: true }))
以上是 express抛出错误,因为“ body解析器不赞成使用undefined扩展” 的全部内容, 来源链接: utcz.com/qa/410440.html