Skip to content

Instantly share code, notes, and snippets.

@stevenbeales
Created February 12, 2019 02:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevenbeales/ab0ec2f5f888fc369a19f0b7ba001f5a to your computer and use it in GitHub Desktop.
Save stevenbeales/ab0ec2f5f888fc369a19f0b7ba001f5a to your computer and use it in GitHub Desktop.
const fs = require('fs');
const JSONToFile = (obj, filename) =>
fs.writeFile(`${filename}.json`, JSON.stringify(obj, null, 2));
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