Categories
Node.js Quick Tips Quick Tips

Name your functions for better stack traces

< 1 min read

If you’re exporting single functions from CommonJS modules in Node.js, improve your stack traces and make debugging easier by naming those functions:

module.exports = function anotherFunction() {
    // ...
};
Screenshot of CommonJS module in Node.js with anonymous functions which result in a less clear error stack trace
Screenshot of CommonJS module in Node.js with a named function which results in a clearer error stack trace