//change the value in the in-memory object content.val1 = 42; //Serialize as JSON and Write it to a file fs.writeFileSync(filename, JSON.stringify(content));