RSSAmplifier

Sridhar Raj Sampath Kumar · Jan 27, 2016

Printing stack trace in nodejs

0
Sign in to vote or save

sridhar.co

January 28, 2016

Debugging an issue can be hard if we don't get the stack trace. Stack trace saves us the time by taking us right to the line number inside a file where the error occurs. Just logging error with plain console.log won't work.

It logs [TypeError: user.getName is not a function]

We got a TypeError when we called a non existing function in the user object. Since user object will be used in multiple files across our application, error type alone will be insufficient. We can enhance this by printing stack to get the exact location of the code causing an issue.

With err.stack, we now know that the code at line number 3 of index.js causes the issue.

Read the original on sridhar.co

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.