I want to fetch a variable from MySQL table and based on the variable value open my web app window. I coded the MySQL connection query at server end of the app. So when the server connection is established the above mentioned flow could happen.
But after fetching the variable value, the code doesn't run forward and in debug mode the cursor ends on being the return value of y.
Someone please help to resolve the issue. Thanks in advance.
#!/usr/bin/env node
'use strict';
require('dotenv').config({silent: true});
var server = require('./app');
var port = process.env.PORT || process.env.VCAP_APP_PORT || 8000;
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
var def = function(){
server.listen(port, function() {
// eslint-disable-next-line
console.log('Server running on port: %d', port);
return;
});
}
var X;
global.x = X;
var mysql = require('mysql');
var mysqlPool = mysql.createPool({
host : 'localhost',
user : 'root',
password : '',
database : 'emp',
debug : true
});
var abc = function(){
mysqlPool.getConnection(function(err, connection) {
connection.query("select exp from empid where id= 12345", function(err, rows){
if(err) {
throw err;
} else {
var y = rows[0].exp;
}
//connection.release();
*return y;*
});
});
}
def();
abc();
if(abc > 2) {
window.location.href = "http://www.w3schools.com";
}
No comments:
Post a Comment