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

97
Views
Javascript destructuring new constructed object when calling a function
const {message, stack} = new Error('NOT GOOD');

logger.error({message, stack});  // <--- calling winston logger

I am wondering if above code can be shorten it into single line, something like:

logger.error({message, stack} = new Error('NOT GOOD'));
UPDATE: the reason why I got this question:

This is how I format the winston log (in typescript):

// Creating file log message format
const logFormat = printf(({ level, message, timestamp, stack }) => {
    return `${timestamp} ${level}: ${stack || message}`;
});

When I call:

logger.error(new Error('NOT GOOD'));

The output is as such:

2022-01-28 12:12:12 error: undefined

But if I:

const {message, stack} = new Error('NOT GOOD');

logger.error({message, stack});  // <--- calling winston logger

It work as intended. Display error message and stack.

about 4 years ago · Juan Pablo Isaza
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!