Last active
January 26, 2020 00:55
-
-
Save skydiver/49754f038c33676e6ed6de94449444a0 to your computer and use it in GitHub Desktop.
[node] save / read json
This file contains hidden or 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
(async () => { | |
const jsonContent = await fs.readFileSync('file_to_read.json'); | |
const object = JSON.parse(jsonContent); | |
console.log(object); | |
})(); |
This file contains hidden or 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
(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