the below nodejs code used for signin page in UI by connecting the MYSQL server previously the code was worked fine but in last two days it showing the error which I attached below. I tried various method of pooling connection but I can't rectify the issue. I hope somenone already overcame from the issue. Kindly please help me.
var mysql = require('mysql');
var express = require('express')
var cors = require('cors')
var app = express()
app.use(express.json())
app.use(cors())
app.post('/signin',(req,res)=>{
var pool = mysql.createPool({
host : '****************************',
user : '*******',
password : '******',
database : '********',
multipleStatements:true,
timeout:60000
});
const sethu = {
Password:req.body.Password,
EmailAddress:req.body.EmailAddress
}
callbackWaitsForEmptyEventLoop = false;
pool.getConnection(function(err, connection) {
connection.query('select o.user_na,o.password,o.user_id,o.grp_id,o.is_admin,o.cli_id, case when
o.master_cli_id =0 then "master" when o.master_cli_id <> 0 and o.is_admin=1 then "admin" when
o.master_cli_id <> 0 and o.is_admin=0 then "user" end as user_type from (select
c.master_cli_id,u.is_admin,u.cli_id,u.user_na,u.grp_id,u.user_id,cast(aes_decrypt(u.password,"
******" )as char(100)) as password from activedash_main.users u inner join
activedash_main.clients c on u.cli_id = c.cli_id inner join activedash_main.admin a on u.cli_id =
a.cli_id where u.user_na="'+sethu.EmailAddress+'" and u.password =
aes_encrypt("'+sethu.Password+'","******"))as o;',function(err,results,fields){
if(err){
res.send(err)
}else{
if(results.length<=0){
res.send('Please check your mail-id and password')
}else{
if(results.length>1){
pool.getConnection(function(err, connection) {
connection.query('select o.user_na,o.password,o.user_id,o.grp_id,o.is_admin,o.cli_id,
case when o.master_cli_id =0 then "master" when o.master_cli_id <> 0 and o.is_admin=1 then
"admin" when o.master_cli_id <> 0 and o.is_admin=0 then "user" end as user_type from (select
c.master_cli_id,u.is_admin,u.cli_id,u.user_na,u.grp_id,u.user_id,cast(aes_decrypt(u.password,
"*******")as char(100)) as password from activedash_main.users u inner join
activedash_main.clients c on u.cli_id = c.cli_id inner join activedash_main.admin a on u.cli_id =
a.cli_id where u.user_na="'+sethu.EmailAddress+'" and u.password =
aes_encrypt("'+sethu.Password+'","*******") AND c.master_cli_id=0)as
o;',function(err,results,fields){
if(err){
res.send(err)
}else{
if(results.length<=0){
res.send('Please check your mail-id and password')
}else{
const length = results.length
if(sethu.EmailAddress===results[0].user_na){
if(sethu.Password===results[0].password){
const cli_id=results[0].cli_id
const grp_id=results[0].grp_id
const user_id=results[0].user_id
pool.getConnection(function(err, connection) {
connection.query('insert into
activedash_main.login(cli_id,user_id,grp_id,login_at)values('+cli_id+','+user_id+','+grp_id+',now())'
,function(err,result,field){
if(err){
res.send('Please check your details')
}else{
res.send(results[0]);
connection.release();
}
})
})
}else{
res.send('Password Incorrect')
}
}else{
res.send('Please check your email-id')
}
// }
}
}
})
})
}else{
const length = results.length
if(sethu.EmailAddress===results[0].user_na){
if(sethu.Password===results[0].password){
const cli_id=results[0].cli_id
const grp_id=results[0].grp_id
const user_id=results[0].user_id
pool.getConnection(function(err, connection) {
connection.query('insert into activedash_main.login(cli_id,user_id,grp_id,login_at)values('+cli_id+','+user_id+','+grp_id+',now())',function(err,result,field){
if(err){
res.send('Please check your details')
}else{
res.send(results[0]);
connection.release()
}
})
})
}else{
res.send('Password Incorrect')
}
}else{
res.send('Please check your email-id')
}
}
}
}
})
})
})
app.listen(5000,()=>{
console.log('Listening to 5000')
})
Error:
TypeError: Cannot read property 'query' of undefined
at F:\Active-Dash\rough\sample.js:73:18
at Handshake.onConnect (F:\Active-Dash\rough\node_modules\mysql\lib\Pool.js:58:9)
at Handshake.<anonymous> (F:\Active-Dash\rough\node_modules\mysql\lib\Connection.js:526:10)
at Handshake._callback (F:\Active-Dash\rough\node_modules\mysql\lib\Connection.js:488:16)
at Handshake.Sequence.end (F:\Active-Dash\rough\node_modules\mysql\lib\protocol\sequences\Sequence.js:83:24)
at F:\Active-Dash\rough\node_modules\mysql\lib\protocol\Protocol.js:404:18
at Array.forEach (<anonymous>)
at F:\Active-Dash\rough\node_modules\mysql\lib\protocol\Protocol.js:403:13
at processTicksAndRejections (internal/process/task_queues.js:79:11)
[nodemon] app crashed - waiting for file changes before starting...
connection.queryin callback function ofpool.getConnection. Can you log err in the callback ofpool.getConnectionand check if there is any error?