Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 am not sending a Status, my code is

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) });  }); 
like image 848
D-W-A Avatar asked May 30 '15 18:05

D-W-A


People also ask

What is the use of res sendstatus () function?

The res.sendStatus () function is used to set the response HTTP status code to statusCode and send its string representation as the response body. Parameter: The statusCode parameter describes the HTTP status code. Returns: It returns an Object.

How to set the response HTTP status code to statuscode in express?

The res.sendStatus () function is used to set the response HTTP status code to statusCode and send its string representation as the response body. Parameter: The statusCode parameter describes the HTTP status code. Returns: It returns an Object. You can visit the link to Install express module. You can install this package by using this command.

What is the difference between send () and sendstatus () methods in Node JS?

send (), sendStatus () and json () method in Node.js Node.js Javascript Web Development Front End Technology The send () and json () functions are used for sending the response to the client directly from the server. The send () method will send the data in a string format, whereas the json () function will send the same in JSON format.

What happens if there is no error in express?

If there is no error the second handler is executed, otherwise Express catches and processes the error. You must catch errors that occur in asynchronous code invoked by route handlers or middleware and pass them to Express for processing. For example:


2 Answers

You could try this:

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

Guys are right - it doesn't allow numbers. Prooflink: http://expressjs.com/4x/api.html#res.send

like image 69
Donskikh Andrei Avatar answered Sep 20 '22 18:09

Donskikh Andrei


This is because you are sending numeric value in the res.send.

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

like image 21
Jerome Miranda Avatar answered Sep 16 '22 18:09

Jerome Miranda