Vishant dhandha Vishant dhandha - 1 year ago 64
Node.js Question

How to convert promise into callback in node js?

Here is simple scenario..

I want to convert these code given in firebase documentation to my api..

How can I convert it to callback function?

var uid = "some-uid";

.then(function(customToken) {
// Send token back to client
.catch(function(error) {
console.log("Error creating custom token:", error);

Here is the link of documentation..

Answer Source

If you want to use node-style callbacks on a promise, invoke them like this:

.then(function(result) {
    callback(null, result);
}, function(error) {

Some promise libraries also have helper functions for that, like Bluebirds .asCallback(callback).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download