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

287
Views
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
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!