node.js fs.exists() will be deprecated, what to use instead?

后端 未结 4 803
我在风中等你
我在风中等你 2021-02-18 13:05

According to the documentation node.js fs.exists() will be deprecated. Their reasoning:

fs.exists() is an anachronism and exists only for historical reasons.

4条回答
  •  无人共我
    2021-02-18 14:08

    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');
       });  
    });
    

提交回复
热议问题