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

91
Vistas
Node-fetch Promise response property prints as undefined

I know similar questions have been asked a bunch (see here and here), but I've tried the solutions mentioned there I'm trying to figure out why my node-fetch response isn't behaving as expected. Here's a simple version of the code:

 fetch(new URL("https://www.stackoverflow.com")).then(theResponse =>{
      console.log("This prints OK: "); 
      console.log(theResponse.headers);
      console.log("But this prints as undefined:");
      console.log(theResponse.headers["content-encoding"]);
      return theResponse;
})

The headers as printed are:

{
'accept-ranges': 'bytes',
'cache-control': 'private',
 connection: 'close',
'content-encoding': 'gzip',
 'content-security-policy': "upgrade-insecure-requests; frame-ancestors 'self' https://stackexchange.com",
etc.
}

Why is theResponse.headers["content-encoding"] returning as undefined?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You need to use the .get method of the Headers object:

console.log(theResponse.headers.get("Content-Encoding"));

Notice that unlike a Map or object property access, it works case-insensitively.

about 4 years ago · Juan Pablo Isaza Denunciar

0

you can also use the method getAll of Headers object it return an array

console.log(theResponse.headers.getAll("Content-Encoding"));

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