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? ?
If you simply determine whether the file exists, it is recommended to use the
fs.existsSync()
method directly, refer to the official APIStat 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.