I am starting in programming with NodeJs and I have a little problem. I'm doing validations for registering new users on a website. And I'm doing the validation modules so that a certain field is not duplicated.
//main.js
var mysql= require('mysql'); //Llamado a MySql
var valida= require('./modulos/validaciones');
var validacion= valida.mail(data,(retorno)=>{
console.log("Se asigna variable+retorno="+retorno);
})
if(validacion){
console.log("Usuario Ya Registrado ="+validacion);
} else {
valida.registra(data,(retorno)=>{
console.log(retorno);
})
}
//validaciones.js
exports.mail= (data,callback)=>{
console.log("Entra en validacion");
var query=conection.query(data.valida_mail,(error,rows)=>{
if (error) throw error;
console.log(rows);
if(rows[0]){
console.log("Email Invalido!");
return true;
callback(true);
} else {
return false;
callback(false);
}
});
};
exports.registra= (data,callback)=>{
/*var query=conection.query(data.sqlquery(), function(error, columna, campos) {
if (error) throw error;
callback("Entra en registro de BD");
console.log(columna);
});*/
callback("Llego al registro!");
};
The issue is that I can not get the true or false value of the function saved in a global variable to be validated if the user registers or not.