You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+52-51Lines changed: 52 additions & 51 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,21 +34,22 @@ API
34
34
35
35
36
36
```js
37
-
var jsonfile =require('jsonfile')
38
-
var file ='/tmp/data.json'
39
-
jsonfile.readFile(file, function(err, obj) {
37
+
constjsonfile=require('jsonfile')
38
+
constfile='/tmp/data.json'
39
+
jsonfile.readFile(file, function (err, obj) {
40
+
if (err) console.error(err)
40
41
console.dir(obj)
41
42
})
42
43
```
43
44
44
-
You can also use this method with promises. The readFile() method will return a promise if you do not pass a callback function.
45
+
You can also use this method with promises. The `readFile` method will return a promise if you do not pass a callback function.
45
46
46
47
```js
47
-
var jsonfile =require('jsonfile')
48
-
var file ='/tmp/data.json'
48
+
constjsonfile=require('jsonfile')
49
+
constfile='/tmp/data.json'
49
50
jsonfile.readFile(file)
50
-
.then(obj=>console.dir(obj)))
51
-
.catch(error=>console.log(error));
51
+
.then(obj=>console.dir(obj))
52
+
.catch(error=>console.error(error))
52
53
```
53
54
54
55
### readFileSync(filename, [options])
@@ -57,8 +58,8 @@ jsonfile.readFile(file)
57
58
-`throws` (`boolean`, default: `true`). If an error is encountered reading or parsing the file, throw the error. If `false`, returns `null` for the object.
`options`: Pass in any `fs.writeFileSync` options or set `replacer` for a [JSON replacer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify). Can also pass in `spaces` and override `EOL` string.
0 commit comments