Created
June 14, 2022 13:45
-
-
Save kulcsarrudolf/f76030ae308a242a2e1c9dfb97f10d5b to your computer and use it in GitHub Desktop.
writeObjectToJson.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const fs = require("fs"); | |
| var Buffer = require("buffer/").Buffer; | |
| const objectToJsonFile = async (targetDirectory, fileName, object) => { | |
| const objectJSON = JSON.stringify(object); | |
| const file = `${targetDirectory}/${fileName}.json`; | |
| try { | |
| const data = new Uint8Array(Buffer.from(objectJSON)); | |
| await fs.promises.writeFile(file, data); | |
| } catch (err) { | |
| console.error(err); | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment