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

161
Views
fs.appendFile does not append to new line

I want to append a string to a new line instead of the end of the current line.

Right now, I have a following code.

fs.appendFile(`data/battle-log.csv`, `${new Date().toLocaleString()},1,0,0\r\n`, 'utf8', function (err) {
    if (err) {
       console.log(err);
    }
});

I open the output in notepad app, and I am getting this...

2021/11/7 16:03:15,1,0,02021/11/7 16:16:18,1,0,02021/11/7 16:28:44,1,0,0

I want this instead

2021/11/7 16:03:15,1,0,0
2021/11/7 16:16:18,1,0,0
2021/11/7 16:28:44,1,0,0

EDIT

Oddly enough however, when I open the csv file in notepad, and remove the seconds from Date string like this...

2021/11/7 16:03:15,1,0,02021/11/7 16:16:18,1,0,0
2021/11/7 16:28,1,0,0   // <- remove 'seconds' from Date string

The next time I run the program, it adds the string to a new line.

2021/11/7 16:03:15,1,0,02021/11/7 16:16:18,1,0,0
2021/11/7 16:28,1,0,0
2021/11/7 16:41:23,1,0,0  // <- added to a new line somehow
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!