Difference between fs.exists and fs.existsSync

谁说我不能喝 提交于 2019-12-12 16:09:55

问题


While working with the file I/O for node I found these two functions(fs.exists and fs.existsSync) to check if a file exists in the system. What are the differences between them?


回答1:


exists is non blocking, and you do subsequent work with the file through a callback.

existsSync is blocking and freezes your whole app while it is working. This can be appealing to new node users because they can continue their code on the next line. However, once you become used to using callbacks, this is a far inferior way to do things.




回答2:


One is working in a synchronize way (wait until finished) and another return immediately and return a promise which has a future value.



来源:https://stackoverflow.com/questions/33969360/difference-between-fs-exists-and-fs-existssync

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!