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?
 
    