Skip to content

Callbacks & Promises

Ariel Rey edited this page Jan 19, 2017 · 1 revision

Callbacks & Promises

We support both. To achieve this and support to Node.js versions previous to 0.11.13 (when native promises were added), we are using internally bluebird.

Callbacks:

library.method(function (err, res) {
    if (err) return console.log(err);
    
    console.log(res);
})

Promises:

library.method().then(function (res) {
    console.log(res);
}).catch(function (err) {
    console.log(err);
});

Use the one that you prefer and adapt to your application.

Clone this wiki locally