【发布时间】:2018-09-14 01:45:01
【问题描述】:
我需要先检查文件是否为空,然后才能放入JSON.parse()。
if (fs.exists('path/to/file')) { // true
return JSON.parse(fs.read('path/to/file'));
}
我知道该文件存在于fs.exists(),但是如何在将其放入JSON.parse() 之前检查该文件是否不包含任何字符串?
JSON.parse(fs.read('path/to/file'));
返回:
SyntaxError: JSON Parse error: Unexpected EOF
【问题讨论】:
标签: javascript phantomjs filesystems fs