Can’t set headers after they are sent due to asynchronous processing? ?

  node.js, question

I haven’t found the problem yet.

app.post('/chart', function(req, res){
 var SQL = 'xxxxxxx';
 connection.query(SQL, function(err, rows){
 res.send(rows);
 })
 })

If you write like this, you will get an error.

If it is written as:

app.post('/chart', function(req, res){
 var SQL = 'xxxxxxxxxx';
 connection.query(SQL, function(err), rows){
 xxxxxxx
 };
 res.send({status:  0 });
 })

This will not make a mistake. – –

None of the previous codes returned data to the foreground.

Can’t set headers after they are sent;
This error indicates that. You did some more writing on a closed connection.
Json () or res.json ()
The underlying code ends with res.end ().
In other words, if you have res.json () followed by res.xxxx ()
The above mistake will be reported.

Your first example above reported an error because you read and write res after response called end ()