Closed abrkn closed 7 years ago
Yeah, I need to fix this...
Even though the docs indicate this:
throws (boolean, default: true). If JSON.parse throws an error, throw the error. If false, returns null for the object.
It's pretty confusing.
Related: https://github.com/jprichardson/node-jsonfile/pull/42
I got this same issue. I need to read an file and if it not exists I want to create one with an empty object. So if the result is null of jsonfile.readFileSync I can create it. But fs is throwing the error with no respect for the 'throws' option.
Maybe it's an idea to create two extra methods, exists and existsSync, and under the hood use fs.stat and fs.statSync?
@jprichardson, you're welcome to merge #42 if you want. I've fixed the merge conflict.
Closed with #42
jsonfile.readFileSync(statePath, { throws: false })