Skip to content

Instantly share code, notes, and snippets.

@collingo
Last active February 2, 2024 13:22
Show Gist options
  • Save collingo/6700069 to your computer and use it in GitHub Desktop.
Save collingo/6700069 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);
}
});
@sodikabdullaev
Copy link

cool thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment