我一直在閱讀示例應用程序嘗試學習節點。我注意到有幾個在boot()中加載模型和控制器時使用readdirSync方法。節點app.js - 同步讀取文件?
例如:
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)
})
這似乎反節點給我。這與節點所喜歡的「嘗試製造一切異步」是相反的。
何時以及爲什麼同步文件讀取是這樣一個好主意?
有沒有這樣的事情,「試圖使一切-async「,你總是使用目前對你來說很方便的工具。 – freakish