Firebase Functions print an object to the console

Viewed 2889

I have this code on the Firebase cloud using functions

peopleDataBase.orderByChild("mCalculateFaceSizeWidth")
                        .endAt(mCalculateFaceSizeWidth())
                        .limitToLast(1)
                        .on("child_added", function(snapshot) {
                       var  person = {
                                "name":snapshot.val().name,
                                "age":snapshot.val().age,
                                "id":snapshot.val().id,
                                "children":snapshot.val().children,
                                "address":snapshot.val().address,
                                "image":snapshot.val().image
                            }

                            if(key != snapshot.key){
                                people += person;
                                key = snapshot.key;
                                console.log("The entire people list:",people);
                            }

                        });

I am trying to print the people object to the console, I have searched for an hour using JSON.stringify and String even $scope and other methods, nothing worked. In the log on the cloud I am getting

2017-07-11T07:55:54.593Z I status: The entire people list: [object Object]

Eventually I want to send the object back to the mobile device but I want to make sure I see the data inside. Ideas?

Thanks Eran

3 Answers

I had similar issue. I had to print it without string concatenation:

console.log("The entire people list:");
console.log(people);

This works for me:

console.log("The entire people list:", JSON.stringify(people));
Related