Based on a quick glance, it appears that the problem here has less to do
with variable scope and more to do with your use of an async function (e.g.
con.query). In the above, your function has likely exited before the
callback has executed, meaning that result never has a chance to be set.
Further, even if your callback did manage to execute, you can't just return
it as though it's in the outer function's scope. You would need to execute
a callback on the outer function or return a promise.
hth,
_howard
On Monday, March 27, 2017 at 5:28:47 PM UTC-7, SURAJ KUMAR CHANDRA wrote:
>
> How do you guys use node js vars. Please refer to red marking. I am
> declaring variable at one place trying to use at another place, simply not
> working.
>
> function login(email,password){ // Returns the login data row
> var email = email.trim().toLowerCase();
> var password = password.trim();
>
> var result = []; //*Declaring here*
>
> //var queryString = "SELECT * FROM users where Email ="+"'"+email+"'"+
> AND Password = +"'"+password+"'";
> var queryString = "SELECT * FROM users where Email ="+"'"+email+"' AND
> Password = '"+password+"'";
>
> //var execQuery = function execQuery(){
> con.query(queryString,function(err,rows){
> if(err) throw err;
>
> // console.log('Data received from Db:\n');
> //result = result.push('SUCCESS','0000','Data',rows)
> //console.log(rows);
> result = rows; // *Want to use here*
> //return rows;
>
> });
>
> con.end();
>
> //}
> //console.log('Outside function block: '+execQuery());
> return result; /*/ want to see here*
> }
>
>
--
Job board: http://jobs.nodejs.org/
New group rules:
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/nodejs/b3173305-1709-49fb-912a-3ee1ef1dbf9b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.