For a reason that I am struggling to find out, I cannot apply conn.end() after my queries in any route.I am starting to think that in some point the involvement of Passport.js configuration causes it because before the query I give conn.state and it seems that there is already an open connection.Error (events.js is not a file I work on, I guess is a standard node_modules factory file)`events.js:183 throw er; // Unhandled 'error' event ^ Error: Cannot enqueue Quit after invoking quit. .Route file on which I try to apply conn.end()var express = require('express'); var router = express.Router(); var dashboard = express.Router(); dashboard.use(function(req, res, next) { console.log(req.method, req.url); next(); }); var dashboard = router.route('/'); dashboard.get(function(req,res,next){ req.getConnection(function(err,conn){ console.log(conn.state, conn.ThreadId) // authenticated, xxxx if (err) return next("Cannot Connect"); var query = conn.query('SELECT SUM(total_price) AS transactions_total FROM transactions WHERE date_created = CURDATE()', function(err,rows){ if(err){ console.log(err); return next("MySQL error, check your query"); } res.render('dashboard', {data:rows}); conn.end(); // causes the described error }); // conn.end(); even tried here }); }); dashboard.all(function(req,res,next){ console.log("route for dashboard executed"); console.log(req.params); next(); }); module.exports = router; .app.jsvar express = require('express'), path = require('path'), bodyParser = require('body-parser'), app = express(), expressValidator = require('express-validator'), session = require('express-session'), passport = require('passport'), flash = require('connect-flash'), passportConfig = require('./config/passport'), dbConfig = require('./config/db'); // skipping code about static files, bodyparser, expressValidator, session, passport passportConfig(passport) /*MySQL connection*/ var connection = require('express-myconnection'), mysql = require('mysql'); app.use( connection(mysql, dbConfig, 'request') ); var dashboard = require('./routes/dashboard.js'); // in this route I apply conn.end() var router = require('./routes/rates.js'); // skipping app.post/app.get code for /login & /logout & isLoggedIn middleware app.use('/', router); app.use('/', dashboard); // issue on that app.get('/', function(req, res) { res.render('./dashboard.ejs'); //issue on that }); module.exports = app; .db config filemodule.exports = { host : 'localhost', user : 'root', password : '', database : 'mydb', debug : false } .Passport.js configurationPastebin link
Submitted May 19, 2018 at 12:45PM by King_Cadmos
No comments:
Post a Comment