Node -express error: express deprecated res.send (status): use res.sendStatus (status) instead

I am trying to send an integer via response.send() , but I keep getting this error

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

I do not send status, my code

 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) }); }); 
+16
express response
May 30 '15 at 18:50
source share
6 answers

You can try the following:

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

Guys are right - numbers are not allowed. Prooflink: http://expressjs.com/4x/api.html#res.send

+40
Sep 16 '15 at 7:22
source share

This is because you are sending a numeric value to res.send.

You can send a json object or convert it to a string.

+10
Jun 24 '16 at 6:45
source share

(as mentioned in the comments)

The manual says :

The body parameter can be a Buffer object, a string, an object, or an array.

Thus, integers are not directly supported and must first be converted to one of these types. For example:

 response.send(String(idTest)); 
+5
Sep 28 '15 at 8:34
source share

Use like that,

 res.status(404).send('Page Not found'); 
+4
Apr 14 '16 at 9:24
source share

Until you send String or Object / Array data, you get an error. The solution converts your data to a string:

 app.get('/runSyncTest', function(req, res) { var number = 5000; res.send((number).toString()); //Number is converted with toString() }); 
+1
Mar 02 '17 at 16:21
source share

Its legacy Express 5 no longer supports signature, as -

 res.json(200, { result: result }); 

Instead, use this method, which means that you only need to change the format for sending responses.

 res.status(status).json(obj) 

Example -

 res.status(200).json({'success' : true, 'result': 'result'}) 
0
May 13 '19 at 9:23
source share



All Articles