console.trace() outputs its result on console.
I want to get the results as string and save them to a file.
I don\'t define names for functions and
I was trying to get Stack Trace as string variable in JavaScript on NodeJS and this tutorial helped me. This will work in your scenario as well except stack trace is printed via Error Object than console.trace().
Code to print stack trace:
function add(x, y) {
console.log(new Error().stack);
return x+y;
}