Vishant dhandha Vishant dhandha - 3 months ago 17
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..


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).