Home > OS >  Nested objects in response not logging to console
Nested objects in response not logging to console

Time:04-04

My server gets a response from another server with a document from a mongodb database with a body similar to

{
    messageDetails: {
        body: "hello"
    },
    customerDetails: {
        cstmrFirstName: 'Random',
        cstmrLastName: 'Name',
    },
}

But the response with the body is being logged to the console as:

{
  messageDetails: [Object],
  customerDetails: [Object],
}

How can I log the full object to the console with each object's properties?

CodePudding user response:

const util = require('util')

console.log(util.inspect(objectName, {showHidden: false, depth: null, colors: true}))

CodePudding user response:

Try console.log(JSON.stringify(body))
Checkout MDN doc JSON.stringify() for more details

  • Related