Skip to content

Instantly share code, notes, and snippets.

@skydiver
Last active January 26, 2020 00:55
Show Gist options
  • Save skydiver/49754f038c33676e6ed6de94449444a0 to your computer and use it in GitHub Desktop.
Save skydiver/49754f038c33676e6ed6de94449444a0 to your computer and use it in GitHub Desktop.
[node] save / read json
(async () => {
const jsonContent = await fs.readFileSync('file_to_read.json');
const object = JSON.parse(jsonContent);
console.log(object);
})();
(async () => {
const data = {
name: 'John Doe',
age: 39,
};
const jsonContent = JSON.stringify(data, null, 4);
await fs.writeFileSync('file_to_read.json', jsonContent, 'utf8', function(err) {
if (err) {
return err;
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment