node-express errror:express deprecated res.send(status):use res.sendStatus(status)instead

我想通过response.send()发送一个整数,但我不断收到此错误

 express deprecated res.send(status): Use res.sendStatus(status) instead 

我不发送状态,我的代码是

 app.get('/runSyncTest' , function(request, response){ var nodes = request.query.nodes; var edges = request.query.edges; if (edges == "" ){ edges = [] } userStory.userStory(nodes,edges); connection.query('SELECT MAX(id) as id FROM report ', function(err,results, fields) { idTest = results[0].id response.send (idTest) }); }); 

有什么build议么?

你可以试试这个:

 res.status(200).send((results[0].id).toString()); 

伙计们是对的 – 它不允许数字。 Prooflink: http ://expressjs.com/4x/api.html#res.send

(如已经在评论中提到的那样)

手册指出 :

body参数可以是一个Buffer对象,一个String,一个对象或者一个Array。

所以整数不直接支持,需要先转换为其中的一种。 例如:

 response.send(String(idTest)); 

像这样使用,

 res.status(404).send(Page Not found'); 

这是因为你在res.send发送数值。

你可以发送一个json对象或将其转换为string。

只要你不发送string或对象/数组数据,你会得到一个错误。 解决scheme将数据转换为string:

 app.get('/runSyncTest', function(req, res) { var number = 5000; res.send((number).toString()); //Number is converted with toString() });