The Problem with Promises and Domains

FAQ

Q: What should I do?

A: Every Restify 4.x app should use bluebird instead of native Promises.

Q: How do I do that?

A: At the beginning of your app (where you load dotenv) you should add the following:

global.Promise = require("bluebird");

Q: Awesome! 🎉 Now I can just use all the neat-o bluebird promise methods!

A: That is not a question. Also, please don't. Please treat every Promise in your app like a native Promise and don't invoke bluebird methods without explicity using bluebird. If you fail to do that, it will be nearly impossible to undo this hack revert this temporary (albeit clever) solution. So, to be clear:

// bad
return new Promise((resove, reject) => {
        // ...
        if (err) {
            reject(err);
        }
        else {
            resolve(true);
        }
    })
    .finally(() => {
        // native promise has no method `finally`
        console.log("finished");
    });

// good
const bluebird = require("bluebird");
return new bluebird((resove, reject) => {
        // ...
        if (err) {
            reject(err);
        }
        else {
            resolve(true);
        }
    })
    .finally(() => {
        // &#x1F44C
        console.log("finished");
    });