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