How to print user details in the console?

I have the following code that get executed (in the client) when I press a button:

console.log("user : " + Meteor.userId())
console.log("user name :" + Meteor.user());

And what I see in the console is the below:
Screen Shot 2020-06-16 at 12.59.26 PM

The user is logged as I can see his _id is printed to the console but I can’t seem to console.log() the user details in a readable format as it shows me [object Object], so my question is, how can I get the user details to be views in the console in a readable format?

Easiest is to log the string "user name: " and the user object separately:

console.log("user name :", Meteor.user());

Note that I’ve replaced the + with ,

What’s happening is with +, it converts everything to strings, using the most basic conversion and concatenation, and Object.prototype.toString() always returns "[object Object]".
With , you are passing the object un-modified to console.log which will allow you to inspect it’s contents

3 Likes

Another option is:

console.log("user: " + JSON.stringify(JSONobject));
1 Like

Try this:

console.log("user: ", JSON.stringify(Meteor.user()));