I am learning nodejs by writing an app to manage my Philips hue lights and I have a problem with the way nodejs works.
I have a function that is supposed to get all ids of the lights:
id = [];
function getLightsId() {
args = {
path: {
"username": "myusername"
}
};
client.registerMethod("getLightState", "http://192.168.0.10/api/${username}/lights/", "GET");
client.methods.getLightState(args, function (data, response) {
for (key in data) {
id.push(key);
}
});
}
The problem is that whenever I want to use my id array, its empty because nodejs didnt processed the getLightsId callback function.
ps : I am using node-rest-client to interact with my API.