DEV Community

Ajay Baraiya
Ajay Baraiya

Posted on • Updated on

Object logging in Console #Node Quick Notes.

Remember we require console to debug javascript so below will be usefull.

  1. Node do not logs objects as javasript does after certain level, to do so use console.log(JSON.stringify(obj, null, 2)); or set require('util').inspect.defaultOptions.depth = null;

  2. if above is hard then just use string format and do below.

// %o tells console.log() to string-format and log obj in its place
console.log('%o', obj);
Enter fullscreen mode Exit fullscreen mode

Top comments (2)

lico profile image
SeongKuk Han

I didn't know the second one :) Thanks

ajaybaraiya6 profile image
Ajay Baraiya

You are welcome, I'm glad you found it useful.