I have a .js
file with just JSON objects exported. Can I read these in update the objects and write them back to the same file? How? I know how to read a .json
file, update it and write it back.
I do something similar on one of my projects but instead of using a JS file I'll store those values in a JSON file. After making your modifications to the object you can do something like this
fs.writeFile('file.json', JSON.stringify(myObj, null, 4), function(err) {
if (err) {
//handle error
}
else {
//handle success
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.