Sunday, 25 February 2018

Passing variables from request module

I need a little help here. I'm new to Node and I'm trying to use the request module and pass a variable named state. The variable works just fine and shows the correct value when I call it from within but if I call it after the }); for the module, it's null. Would someone be able to point me in the right direction?Thanks. request({url:'http://ift.tt/2oo8AM2 queryData.apikey,method:'GET',json:requestmsg},function(error,response,body){ if (cmd == 'lightstatus') { var state = body.result[0].deviceTypeMap.garageLight_7.at.lightState.value console.log("lightstate:" + state) } else if (cmd == 'doorstatus') { var state = body.result[0].deviceTypeMap.garageDoor_7.at.doorState.value console.log("doorstate:" + state); } }); response.end(state)

Submitted February 25, 2018 at 07:54AM by madj42

No comments:

Post a Comment