Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

151
Views
Nested objects in response not logging to console

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?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

const util = require('util')

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

over 4 years ago · Santiago Trujillo Report

0

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

over 4 years ago · Santiago Trujillo Report

0

You can use console.dir. To print with unlimited depth, use {depth: null} option:

console.dir(body, {depth: null});
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!