Global Variable Is Not Updating Using Nodejs
I have below global variable and trying to update in diffrent methods var companyName; In this method i am getting company name and can able to print the companyName in terminal v
Solution 1:
try to change this:
once(myDB);
console.log('Company inside db call :' + companyName);
to :
once(myDB).then(v=>console.log('Company inside db call :' + companyName)).catch(v=>console.log('error',v))
because once(myDB)
is async
and returns a promise
you can put the callback in the promise.then(v=>/*your callback*/)
Post a Comment for "Global Variable Is Not Updating Using Nodejs"