javascript - Can stat() access() open() readFile() in node.js determine whether a file exists?
某草草
某草草 2017-06-24 09:43:34
0
2
789

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? ?

某草草
某草草

reply all(2)
伊谢尔伦

If you simply determine whether the file exists, it is recommended to use the fs.existsSync() method directly, refer to the official API

漂亮男人

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!