Error [err] is reported when redirecting_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client

When nodejs connected to mysql database, there was a problem that the data was received normally at the first connection, but when the page redirection was updated, it was wrong, and the node service would be disconnected. As shown in figure

error code is as follows:

after searching online, it was found that res.send() contains res.end() method. After calling res.end() once, the data returned normally, but res.end() was executed at the same time
The solution
Will res. The send (); Just comment it out.
, but then it reports an Error, as shown in figure

Error: Cannot enqueue Quit after invoking Quit.
I use the mysql module, because I call connection.end() frequently; This error occurred, so the final code is as follows

//Search School List
router.get('/school', function(req, res, next) {
  connection.query("select * from school",function (err, result) {
      // res.send(err.message);
      // res.send(result);
  // connection.end();
  // res.send('respond with a resource');

Read More: