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) }); });
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.
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.
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.
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:
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
This is because you are sending numeric value in the res.send.
You could send a json object or convert it to string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With