NodeJS Q and module

89 Views Asked by At

I have two files, layer-token.js and server.js.

layer-token generates a JWT token, I am using promises using Q to go through the process step by step, everything work fine and the token is generated.

My problem is how to pass the token back to server.js, currently the value of LayerSessionToken comes out as [Object Promise], how do I access the actual value?

server.js

LayerSessionToken = layerToken.generateToken();

layertoken.js

var returnSessionToken = function(Sessiontoken) {
return Sessiontoken;

}

module.exports = {
    generateToken : function()
    {
       LayerToken= getNonce()
       .then(getIdentityToken)
       .then(getSession)
       .then(returnSessionToken)
       .fail(function (error) {
            response.write('Computer says no, ' + error.message);
       });
     return LayerToken
    }
}
1

There are 1 best solutions below

0
On BEST ANSWER

Your layertoken.js returns a Promise LayerToken. To get the actual value you call .then on it

LayerSessionToken = layerToken.generateToken();
LayerSessionToken.then(function(actualValue){
    // do something with actualValue
});

More info on how Promises work