Estoy tratando de almacenar cada mensaje nuevo en un archivo js pero no funciona correctamente. no me sale ningun error ni nada...
¿Alguien podría ayudarme con una solución? :)
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; });Mi 1.js antes:
export const messages = [ { "id": 1, "author": "Knocklive", "content": "TextXYZ" }, { "id": 2, "author": "Knocklive", "content": "TextXYZ" }, { "id": 3, "author": "Knocklive", "content": "TextXYZ" }, ]Cómo debería verse después de la acción:
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" }, ]