update: writeFile changed to writeFileSync

This commit is contained in:
shanyuhai123
2020-06-15 22:52:01 +08:00
parent 35ac0b27b2
commit c0e1c9332d

View File

@ -5,12 +5,12 @@ tags: node,json,intermediate
Writes a JSON object to a file.
Use `fs.writeFile()`, template literals and `JSON.stringify()` to write a `json` object to a `.json` file.
Use `fs.writeFileSync()`, template literals and `JSON.stringify()` to write a `json` object to a `.json` file.
```js
const fs = require('fs');
const JSONToFile = (obj, filename) =>
fs.writeFile(`${filename}.json`, JSON.stringify(obj, null, 2));
fs.writeFileSync(`${filename}.json`, JSON.stringify(obj, null, 2));
```
```js