在Node.js上进行同步读取或写入? [英] Synchronous read or write on Nodejs?

查看:69
本文介绍了在Node.js上进行同步读取或写入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么以及何时我们应该在Node.js上使用 read/writeFileSync 而不是 asynchronous ,特别是对于服务器应用程序呢?

Why and when should we prefer read/writeFileSync to the asynchronous ones on Nodejs in particular for server applications?

推荐答案

由于它们正在阻塞函数,因此您应该在生产环境中更喜欢异步版本.

For them are blocking functions, you should ever prefer the async versions in production environments.

无论如何,在应用程序的引导过程中使用它们可能是有意义的,例如,如果您用于从文件加载配置,并且不想让完全初始化的组件与部分初始化的组件进行交互,或者在这种情况下将它们设计为能够相互配合.

Anyway, it could make sense to use them during the bootstrap of your application, as an example if you use to load configurations from files and you don't want either to let your fully initialized components to interact with partially initialized ones or design them to be able to work with each other in such a case.

我看不到它们有任何其他有意义的用途.

I cannot see any other meaningful use for them.

这篇关于在Node.js上进行同步读取或写入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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