According to the documentation node.js fs.exists() will be deprecated. Their reasoning:
fs.exists() is an anachronism and exists only for historical reasons.
Here is example by using fs.stat
:-
fs.stat('mycustomfile.csv', function (err, stats) {
console.log(stats);//here we got all information of file in stats variable
if (err) {
return console.error(err);
}
fs.unlink('mycustomfile.csv',function(err){
if(err) return console.log(err);
console.log('file deleted successfully');
});
});