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');
});