3
I have a method called readFileCredentials
which aims to open a file and return the data that was inside that file, follows the code of that 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 built this code:
try{
readFileCredentials('arquivo.txt', function(err, data){
console.log('Abriu');
});
}catch(err){
console.log('Não abriu');
}
The read is working, however, when I send a wrong file name, so there is an error, the catch is not triggered, what is wrong?
I didn’t know this, it’s nice the JS do the right thing that is hard to find in other languages. Pity that the example of link gives a
throw
spoiling everything :D (of course there is situation that thethrow
may be suitable). Ah, it’s Node, so I didn’t know.– Maniero
@bigown is the Node has taken some interesting steps for better compared to the native JS and the way to treat files.
– Sergio
I imagine, because the normal JS in browser has to be really limited :)
– Maniero