Created
February 12, 2019 02:33
-
-
Save stevenbeales/ab0ec2f5f888fc369a19f0b7ba001f5a to your computer and use it in GitHub Desktop.
This file contains 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'); | |
const JSONToFile = (obj, filename) => | |
fs.writeFile(`${filename}.json`, JSON.stringify(obj, null, 2)); |
This file contains 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
JSONToFile({ test: 'is passed' }, 'testJsonFile'); // writes the object to 'testJsonFile.json' | |
Writes a JSON object to a file. | |
Use fs.writeFile(), template literals and JSON.stringify() to write a json object to a .json file. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment