Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

125
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!