express deprecated req.param(name):使用req.params,req.body或req.query代替app.js:34:22

时间:2016-11-27 17:08:25

标签: node.js

我是node.js的新手并开发了以下应用程序。在这个应用程序中,我期待价值' isAdmin' :真的在回应,但我不明白。相反,我看到以下错误为什么?

express deprecated req.param(name): Use req.params, req.body, or req.query instead app.js:34:22
express deprecated req.param(name): Use req.params, req.body, or req.query instead app.js:35:26

肯定遗漏了一些东西。请指导。

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


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


function authUser(request, response, next){
    var user = {
        name : 'Raj',
        admin : true
    };

    request.user = user;
    next();
};

app.use(authUser);

app.get('/', function(request, response){
    response.send({
        foo : 'bar',
        person : 'Raj',
        isAdmin : request.params.user.admin
    });
});


app.post('/doStuff', function(request, response){
    var param = request.param('foo');
    var firstName = request.param('firstName');
    response.send({
        foo : param,
        firstName : firstName
    });
});

app.listen(3000); 

enter image description here

1 个答案:

答案 0 :(得分:2)

这是因为从Express v4.11.0

开始不推荐使用SELECT AVG(E.SAL),MIN(E.SAL),MAX(E.SAL),SUM(E.SAL),E.DEPTNO,COUNT(*) FROM EMP E, SALGRADE S WHERE S.GRADE=1 OR S.GRADE=2 GROUP BY E.DEPTNO;

您应该使用标准对象点表示法req.params('firstName')

req.params.firstName