Skip to content

Instantly share code, notes, and snippets.

@SiestaDigital
Forked from collingo/writeJsonToFile.js
Created December 20, 2019 23:41
Show Gist options
  • Select an option

  • Save SiestaDigital/e51ab3e5c56e3c5479e52e43b03aed2c to your computer and use it in GitHub Desktop.

Select an option

Save SiestaDigital/e51ab3e5c56e3c5479e52e43b03aed2c to your computer and use it in GitHub Desktop.
Save pretty printed json to file in node
var outputLocation = require('path').resolve(__dirname, 'file.json');
require('fs').writeFile(outputLocation, JSON.stringify(data, null, 4), function(err) {
if(err) {
console.log(err);
} else {
console.log("JSON saved to "+outputLocation);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment