【发布时间】:2018-05-27 02:39:42
【问题描述】:
我在使用 Node.js 进行异步/等待时遇到问题。当我尝试这个时:
function Read_Json_File() {
fs.readFile('import.json','utf-8',(err, data) => {
if (err) throw err;
json_data = JSON.parse(data);
return json_data;
});
}
async function run_demo() {
let get_json_file = await Read_Json_File();
console.log(get_json_file);
}
run_demo();
它返回 undefined 而不是文件中的 JSON。为什么不等待文件读取完成?
【问题讨论】:
标签: javascript node.js async-await es6-promise ecmascript-2017