Am new to Javascript and node.js. Please help me resolving the below issue . I want to update the key 'title' in 'testdata.json' file for the set 'LANG>TEST2>Default' .
testdata.json :
{
"LANG": {
"TEST1": {
"Default": {
"key1": "value1",
"key2": "value2"
},
"Set1": {
"key1": "value1",
"key2": "value2"
}
},
"TEST2": {
"Default": {
"key1": "value1",
"key2": "value2",
"title": "test-name-05252020-4786",
}
},
}
}
I have the below function but its throwing the error as :
TypeError: fileName.put is not a function
writeToJSON= function(){
const fs = require('fs');
const fileName = './testdata';
let title = "test-name-06052020-1712";
fileName.put(title);
fs.writeFile(testdata.json, JSON.stringify(testdata), function writeJSON(err) {
if (err) return console.log(err);
console.log(JSON.stringify(testdata));
console.log('writing to ' + fileName);
});
fileName.push(title)supposed to achieve?putinstead ofpush. What does "to be updating the title" mean? What title???