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

283
Vistas
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 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