Mamun Reza
Mamun Reza

Reputation: 618

Difference between fs.exists and fs.existsSync

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?

Upvotes: 4

Views: 5013

Answers (2)

trex005
trex005

Reputation: 5115

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.

Upvotes: 9

omer727
omer727

Reputation: 7691

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

Upvotes: 1

Related Questions