index.js:
$.ajax({
type:'POST',
url: 'http://localhost:3000/login',
dataType: 'application/json',
data: {username: username, password: password}
})
.done(data => {
console.log(data);
});
on my api node:
app.post('/login',async function(req,res){
email = req.body.username;
password = req.body.password;
return await db.find(email,password);
});
in the db function:
module.exports.find = async function(email,password){
search(email,password).then(a => {
return a;
});
};
function search(email,password){
return new Promise((resolve,reject) => {
table.find({where: {email: email, password:password}}).done(function(data,err){
if(data != "" && data != null)
resolve(data);
});
});
}
The function does not return the pro date value although I have used async await to wait for the answer and only come back when I get the same one, can anyone help?