Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

132
Vistas
next js trying to store data in file

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"
    },
]
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda