fs.exists, fs.existsSync - why are they deprecated?

前端 未结 7 586
遥遥无期
遥遥无期 2021-01-07 20:06

I noticed that the official node documentation says something startling about fs.exists:

\"fs.exists() is an anachronism and exists only

7条回答
  •  情深已故
    2021-01-07 20:10

    I was searching for a solution to this issue and found that fs.exists and fs.existsSync was deprecated. This seems to work well in my senario

    fs.readFile(filename, 'utf8', function(err,data){
        // the err variable substitutes for the fs.exists callback function variable
        if (!err){
            // do what you planned with the file
            console.log(data)
        }else{
            // handle the non-existence of the file
            console.log('File does not exist!');
        }
    });
    

提交回复
热议问题