I am writing a simple script to retrieve a password from the table and validate in node.js Here is the script
module.exports = {
login: function (email, pass) {
var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database('test.db');
db.get("SELECT password FROM users WHERE user_email = ?", email, function(err, row) {
if (err !== null) {
console.log("An error has occured");
return "error";
} else if(row.password === pass) {
console.log("success");
return "success";
} else {
console.log("Incorrect password");
return "failure";
}
});
}
};
The console log statements are correct when the if else cases are evaluated. However the return value is undefined. I do not understand why the return value is undefined if the logging is done correctly.