How do I convert an Error object in node js to a string properly?
To get the full stack use stack
property of the Error
object:
console.log(error.stack)
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/stack
I thought I had to use JSON for this problem because of the way the Error object was formatted. How I solved this one was just to use
err.toString()
For future reference, just in case you wish to extract the Error messsage. Use error.message
to extract the message. Here is a reference: https://nodejs.org/api/errors.html#errors_error_message