update: writeFile changed to writeFileSync
This commit is contained in:
@ -5,12 +5,12 @@ tags: node,json,intermediate
|
|||||||
|
|
||||||
Writes a JSON object to a file.
|
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
|
```js
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const JSONToFile = (obj, filename) =>
|
const JSONToFile = (obj, filename) =>
|
||||||
fs.writeFile(`${filename}.json`, JSON.stringify(obj, null, 2));
|
fs.writeFileSync(`${filename}.json`, JSON.stringify(obj, null, 2));
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|||||||
Reference in New Issue
Block a user