1

I know there is a lot of stuff out there explaing the concepts but I am still confused why my node.js example does not work.

I have a main function

function main(){
login()
    .then(
        function(result) {
            return getMyInfo();
        }
    );

and two API calls (getMyInfo and login) like this:

function login(){
    const options = {
        ...
        },
    };
    return rp(options);
}

Now I want to call my main function from another file

main()
    .then(
        function(thisIsWhatINeed) {
            console.log(thisIsWhatINeed);
        }
    );

Somehow this still returns undefined for me, can you help you finding out why? In my opinion both login() and getMyInfo() return a promise and therefore main() also returns a promise because it return getMyInfo..

solaire
  • 475
  • 5
  • 22

1 Answers1

1

Return the promise from your main function:

function main() {
   return login().then(function(result) {
       return getMyInfo();
   });
}
Faly
  • 13,291
  • 2
  • 19
  • 37
  • Ok, thanks this worked. I thought if i have return getMyInfo() in the main(), then this will be the return value of main() – solaire Jan 25 '18 at 13:37