0

From the documentation of Q (the Javascript promise library):

Q.longStackSupport = true;

This feature does come with somewhat-serious performance and memory overhead, however. If you're working with lots of promises, or trying to scale a server to many users, you should probably keep it off. But in development, go for it!

I find myself always writing code like this:

var Q = require('q');
Q.longStackSupport = true;

However, if I decided to turn off longStackSupport, I would have to touch a lot of files in my code.

So, I wonder if there is a more elegant solution:

  • Is there a recommended pattern when including Q?
  • Is it sufficient to call Q.longStackSupport only once?
Philipp Claßen
  • 41,306
  • 31
  • 146
  • 239
  • 1
    Honestly I'd consider Bluebird if I were you, it has long stack traces that are actually meaningful. – Benjamin Gruenbaum Jun 04 '14 at 22:12
  • @BenjaminGruenbaum Thanks a lot, very interesting. I was a bit skeptial first, as there are so many implementations to choose from. After having read more about it, I'll definitely give it a try. – Philipp Claßen Jun 06 '14 at 19:39

1 Answers1

2

Yes, it is sufficient to only call it once in one place.

In init.js, or whatever your root file is, I would put

if (process.env.NODE_ENV === "development") {
    Q.longStackSupport = true;
}

Then this will automatically enable it if you have the NODE_ENV environment variable set to development.

$ export NODE_ENV=development
$ node init.js
Esailija
  • 138,174
  • 23
  • 272
  • 326