【发布时间】:2020-05-05 02:11:34
【问题描述】:
我的文件是:
import * as fs from 'fs'
async function loadModels() {
console.log('here i am!')
const modelFiles = fs.readFileSync(__dirname + '/models')
console.log(modelFiles)
}
(async () => {
loadModels()
})()
在package.json,我有:
"fixtures": "tsc fixtures/index"
所以当我运行yarn fixtures 时,我得到:
yarn fixtures
yarn run v1.22.4
$ tsc fixtures/index
✨ Done in 8.78s.
为什么我的loadModels 不运行?
【问题讨论】:
-
为什么文件系统
fs需要异步/等待? -
loadModels确实以这种结构运行。 See playground. -
附带说明:此代码中的任何地方都不需要 async 关键字。
标签: javascript node.js typescript async-await