我的问题的答案可能很明显,但我找不到。
我实际上想在 nodeJS 应用程序上读取一个 json 文件。
var accRead = fs.readFile(__dirname + '/accounts.JSON', { endoding: 'utf8' }, function(err, data) {
if (err) throw err
if (data) return JSON.parse(data)
})
我写了这个,我不明白为什么它返回未定义,我检查了Json文件并且有一些数据。
请尝试以下操作:
const accounts = () => fs.readFileSync(__dirname + '/accounts.json', { endoding: 'utf8'})
const accRead = JSON.parse(accounts())
/*Logging for visualization*/
console.log(accRead)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句