Código Javascript:
Ver original
module.exports={ isBanned:function(ip){ var fs=require('fs'); var fileName='./views/bannedList.txt'; fs.exists(fileName,function(exists){ if(exists){ fs.stat(fileName,function(err,stats){ if(err)throw err; fs.open(fileName,'r',function(err,fd){ var buffer=new Buffer(stats.size); fs.read(fd,buffer,0,buffer.length,null,function(err,bytesRead,buffer){ bannedips=buffer.toString('utf8',0,buffer.length); bannedips=bannedips.split('|||'); for(var a=0;a<bannedips.length;a++){ console.log(ip); console.log(bannedips[a]); if(bannedips[a]==ip)return true;//Aqui devuelvo true pero en la funcion cellback de fs.read y yo quiero hacer lo en la funcion isBanned } return false; }); }); }); }else{ console.log('Banned file don\'t exists. Exit program!'); process.exit(code=0); } }); } }
Alguna idea