I have a method called readFileCredentials
that has the purpose of opening a file and returning the data that was inside that file, it follows the code of this method:
readFileCredentials = function(file, cb){
var _path = 'data-source/credentials/' + file;
fs.readFile(_path, 'utf8', function(err, data){
cb(err, data);
});
};
And to call this method, I've built this code:
try{
readFileCredentials('arquivo.txt', function(err, data){
console.log('Abriu');
});
}catch(err){
console.log('Não abriu');
}
The reading is working, however, when I send a wrong file name, so that there is an error, catch is not triggered, what's wrong?