Whenever my node.js script has an uncaught exception. I'd like to be able to dump all the local variables to the console implicitly so that I can have a snapshot of all the values the moment anything went wrong.
Right now I can do this with visual code by having a debugger running, but is this possible to do using just code?
If not, what would be the best way to invoke a debugger to attach to the node script and dump the variables when an exception occurs?
Currently the built in node.js debugger has the watch() method for getting the variable values on an exception, but it requires that you implicitly specify the variable before the exception occurs.
There is the chrome v8 debugger using --inspect argument and visiting chrome://inspect/ in chrome, but that would require automating chrome using the Chrome DevTools Protocol.
It also requires an instance of chrome to be running which is too resource intensive on a VPS that has the minimum specs.
What is the best way to dump the local variables to a log file when something goes wrong?