问题
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