-1

I'm having troubles with making a variable within a function global. This would work outside of the app.post('/init...) below

Here is my code:

const cloudlyn = require ('cloudlyn/demon')

app.post('/init', function(req, res){
    
   cloudlyn.fly(customList, function(err, demonid){


        if (err){
          console.log(err)
        }if (demonid){

        console.log(demonid)

     //  everything works until this point.
        userDemonid = demonid

        // the problem is raising this variable to global scope. 
        // I understand not using const, var or let helps accomplish this
        }

   });

   // then I have another function that needs this demonid.
   // Notice that this is within the same app.post('/init'...)

   const migrateCloudlyn = cloudlyn.migrate({
    // I am trying to access the variable userDemonid 
     demonid = userDemonid,
     plan  = basePlan

   }

});

The variable userDemonid is somewhat not available globally, any idea why this is so? What am I doing wrongly?

Paschal
  • 725
  • 1
  • 9
  • 17
  • Does this answer your question? [How do I return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – Ivar Sep 19 '20 at 09:28
  • use `global.userDemonid` to set a variable to global scope – aRvi Sep 19 '20 at 09:29

1 Answers1

-1

You can use cookies or sub pages. Or debug function priority. "require()" function a interpreter. If defined a global function in 'cloudlyn/demon' it name is not your defined address. You can not import js code on DOM runtime. Try to access "cloudlyn.globalfoo".