fs.exists和fs.existsSync之间的区别 [英] Difference between fs.exists and fs.existsSync

查看:451
本文介绍了fs.exists和fs.existsSync之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用节点的文件I/O时,我发现了这两个函数( fs.exists 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?

推荐答案

存在是非阻塞的,您可以通过回调对文件进行后续工作.

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

existsSync正在阻止并冻结您的整个应用程序.这对新节点用户可能很有吸引力,因为他们可以在下一行继续他们的代码.但是,一旦习惯了使用回调,这是做事的劣等之举.

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.

这篇关于fs.exists和fs.existsSync之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆