Created
November 8, 2019 12:47
-
-
Save dominikkaegi/611b9fc40492168fe739ea82a0e2d5c2 to your computer and use it in GitHub Desktop.
Takes a JS Object and Turns it into a JSON object and writes it into a specified file.
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'); | |
| function jsObjectToJSON(filename, data) { | |
| const formattedString =JSON.stringify(data, null, 2) | |
| fs.writeFile(filename, formattedString, function(err) { | |
| | |
| if(err) { | |
| return console.log(err); | |
| } | |
| | |
| console.log("The file was saved!"); | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment