Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

95
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda