Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

163
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda