My understanding is:
stat() is to obtain file information;
access() tests whether the file is available;
open() opens the file;
readFile() reads the file;
Then I can determine whether the file is available when using readFile(), but I see that some people write static resource servers first using the open() method. Isn’t this redundant? Are there any other considerations here? ?
伊谢尔伦2017-06-24 09:45:34
If you simply determine whether the file exists, it is recommended to use the fs.existsSync()
method directly, refer to the official API
漂亮男人2017-06-24 09:45:34
Stat is to obtain file information and is usually not used to determine whether the file is available.
Access is best suited to determine whether a file is available.
There is a big difference between open and readFile. Open can read and write. It can also create a file or directly fail based on whether the file exists.