Skip to content

Instantly share code, notes, and snippets.

@Ugarz
Created December 6, 2018 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ugarz/186456a1bbccd4d770c7a6576f31d48f to your computer and use it in GitHub Desktop.
Save Ugarz/186456a1bbccd4d770c7a6576f31d48f to your computer and use it in GitHub Desktop.

Bluebird

Use bluebird with another library

You can override another Promise from a library like node-fetch with bluebird.

var fetch = require("node-fetch");
var Bluebird = require("bluebird");

fetch.Promise = Bluebird;

const url = "https://reqres.in/api/users?page=2"

Bluebird.config({
    longStackTraces: true,
    warnings: true
})

function customFunction(customUrl) {
    return fetch(customUrl)
        .then(res => res.json())
        .then(json => {
            console.log('Fresh data here!')
            return json
        });
}

customFunction(url)
    .then(response => {
        console.log('response', response)
    })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment