【发布时间】:2012-05-22 19:23:50
【问题描述】:
我一直在阅读示例应用程序尝试学习节点。而且我注意到有几个在 boot() 上加载模型和控制器时使用 readdirSync 方法。
例如:
var models_path = __dirname + '/app/models'
var model_files = fs.readdirSync(models_path)
model_files.forEach(function(file){
if (file == 'user.js')
User = require(models_path+'/'+file)
else
require(models_path+'/'+file)
})
这对我来说似乎是反节点。这与节点所支持的“try-to-make-everything-async”相反。
这样的同步文件读取何时以及为何会是一个好主意?
【问题讨论】:
-
没有“try-to-make-everything-async”这样的东西。您总是使用目前方便的工具。
标签: javascript node.js asynchronous