Skip to content

Commit d199491

Browse files
authored
Merge pull request #66 from mawni/update-docs-include-append
Update readme to include append examples
2 parents 00b3983 + 642ab63 commit d199491

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,20 @@ jsonfile.writeFile(file, obj, {spaces: 2}, function(err) {
8585
})
8686
```
8787

88+
**appending to an existing JSON file:**
89+
90+
You can use `fs.writeFile` option `{flag: 'a'}` to achieve this.
91+
92+
```js
93+
var jsonfile = require('jsonfile')
94+
95+
var file = '/tmp/mayAlreadyExistedData.json'
96+
var obj = {name: 'JP'}
97+
98+
jsonfile.writeFile(file, obj, {flag: 'a'}, function (err) {
99+
console.error(err)
100+
})
101+
```
88102

89103
### writeFileSync(filename, obj, [options])
90104

@@ -110,7 +124,18 @@ var obj = {name: 'JP'}
110124
jsonfile.writeFileSync(file, obj, {spaces: 2})
111125
```
112126

127+
**appending to an existing JSON file:**
128+
129+
You can use `fs.writeFileSync` option `{flag: 'a'}` to achieve this.
130+
131+
```js
132+
var jsonfile = require('jsonfile')
133+
134+
var file = '/tmp/mayAlreadyExistedData.json'
135+
var obj = {name: 'JP'}
113136

137+
jsonfile.writeFileSync(file, obj, {flag: 'a'})
138+
```
114139

115140
### spaces
116141

0 commit comments

Comments
 (0)