diff --git a/CHANGES.md b/CHANGES.md index cc8d9c3d..14e9c15a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,8 @@ ## 1.1.0 + - Adds support for enabling long stack traces in node.js by setting + environment variable `Q_DEBUG=1`. - Introduces the `tap` method to promises, which will see a value pass through without alteration. - Use instanceof to recognize own promise instances as opposed to diff --git a/README.md b/README.md index 9a9b9848..b10ea043 100644 --- a/README.md +++ b/README.md @@ -843,6 +843,15 @@ stack trace! This is very helpful for debugging, as otherwise you end up getting only the first line, plus a bunch of Q internals, with no sign of where the operation started. +In node.js, this feature can also be enabled through the Q_DEBUG environment +variable: + +``` +Q_DEBUG=1 node server.js +``` + +This will enable long stack support in every instance of Q. + 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! diff --git a/q.js b/q.js index 5c1303ca..5e978254 100644 --- a/q.js +++ b/q.js @@ -474,6 +474,11 @@ Q.nextTick = nextTick; */ Q.longStackSupport = false; +// enable long stacks if Q_DEBUG is set +if (typeof process === "object" && process && process.env && process.env.Q_DEBUG) { + Q.longStackSupport = true; +} + /** * Constructs a {promise, resolve, reject} object. *