I want to use bluebird's implementation of the Promise/A+ open standard and override native ES6 Promises. I also want the bluebird implementation to be available everywhere in my subsequently imported modules without having to require it in every single one of them. Bluebird's Getting started page tells me to:
var Promise = require("bluebird");
, which results in overriding the native Promise element. Because bluebird is a superset of the spec, it will not break existing code and is thus supposed to be safe to use.
However, because I know it's considered bad practice to:
, I'm wary when I want to include this in the base script of a node app:
import Promise from 'bluebird';
global.Promise = Promise;
Is this a bad practice? Should I stick to importing bluebird in every single file?
I have done this hundreds of times in my code over the last 4 years and so have plenty others among the 10 million monthly downloads.
It is officially supported to swap the native implementation with bluebird.
I do
const Promise = require("bluebird");
On a per-file basis. Note that usuaslly you can promisify your APIs once and then generally avoid calling Promise
- calling at most .resolve
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With