I'm trying to store every new message to a js file but it doesn't work properly. I don't get any errors or anything...
Could somebody help me with a fix? :)
const newmessage = {
"id": 1,
"author": "Knocklive",
"content": input
}
alert(JSON.stringify(newmessage))
fs.writeFileSync("./data/messages/" + chatroomid + ".js", JSON.stringify(newmessage, null, 2) , (err) => {
if (err) throw err;
});
My 1.js before:
export const messages = [
{
"id": 1,
"author": "Knocklive",
"content": "TextXYZ"
},
{
"id": 2,
"author": "Knocklive",
"content": "TextXYZ"
},
{
"id": 3,
"author": "Knocklive",
"content": "TextXYZ"
},
]
How it should look like after the action:
export const messages = [
{
"id": 1,
"author": "Knocklive",
"content": "TextXYZ"
},
{
"id": 2,
"author": "Knocklive",
"content": "TextXYZ"
},
{
"id": 3,
"author": "Knocklive",
"content": "TextXYZ"
},
{
"id": 0,
"author": "namexy",
"content": "contentxyz"
},
]