var fs = require('fs')
2- Define the object to be added to the JSON file
var data = {
  name: "rafael"
}
3- Use filesystem's writeFile() function to write into a custom "data.json" file
fs.writeFile("./data.json", JSON.stringify(data), (err) => {
  console.log("write successful", err)
})
Where: JSON.stringify function saves the data as a stringThat's it!
 
 
No comments:
Post a Comment