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

282
Visualizações
How to log node.js on crash to a file

I have a Discord Bot coded with Node.js. I added a restart command into it when it crashes so I can maintain it on, but randomly every 2-3 times in 24 hours it just restarts.

It might be worth mentioning that I am using replit hacker plan to host it for now.

I don't know -the reason yet, so what I want to do is:

I want to export the traceback/error log into a text file or anything similar so when it crashes I can go through it and try to debug.

Is there an actual way to do so?

I looked for some different ways online and I found this but it didn't seem to work for me since the bot restarted twice this night and no logs. I might just don't know how to use it properly though.

Please help me!

const util = require('util');
const fs = require('fs');
var log_file_err=fs.createWriteStream('./logs/error.txt',{flags:'a'});  

process.on('uncaughtException', function(err) {
console.log('Caught exception: ' + err);
log_file_err.write(util.format('Caught exception: '+err) + '\n');
});
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