I'm trying to get value which I got from select sql query. But when I return my value, it shows undefined. Sorry I'm new to nodejs.I know it's an async function but I'm lost here. Tried even assigning it to another value by using a function. but still no luck. Im new to this so sorry about that.
const getAns = (uname) => {
const query = "SELECT ans FROM users WHERE username = ?";
// Value to be inserted
const username = uname;
// Creating queries
db.query(query, username, (err, rows) => {
if (err) throw err;
return rows[0].ans;
});
};
My other code which tries to get value is like this
const getData=()=>{
const ans=getAns();
console.log(ans)
}
When tried above code it shows 'undefined'.