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) {
if(err){
// res.send(err.message);
res.json({
status:"1",
msg:err.message
});
return;
}else{
// res.send(result);
res.json({
status:"0",
msg:result
});
}
});
// connection.end();
// res.send('respond with a resource');
});