I tried to close the connection for the below query by using connection.close(). but it is not working, so how to close connection inside route file
var express = require('express');
var router = express.Router();
var connection = require('../database.js');
var db = require('../database.js');
/* GET home page. */
router.get('/', function(req, res, next) {
connection.query("Select users..... ",function(err,supervisorrows) {
if(err){
req.flash('error', err);
res.render('View',{page_title:"Users - Node.js",supervisor:''});
}else{
res.render('View',{page_title:"Users - Node.js",supervisor:supervisorrows.recordset});
}
});
module.exports = router;
According to mysql npm docs There are two ways to end a connection :
connection.end() methodconnection.destroy() methodThe first one will make sure all previously enqueued queries are still before sending a COM_QUIT packet to the MySQL server.
The second one terminates a connection immediately and guarantees that no more events or callbacks will be triggered for the connection.