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

230
Vistas
what is the purpose of express res.get(field) method?

I saw some code examples about using express res.get(field)

Is it for debugging purpose or there are other use cases for it?

the code examples I saw looks like this :

var express = require('express');
var app = express();
var PORT = 3000;

// Defining an endpoint
app.get('/api', function(req, res){

   // Setting the Content-type
   res.set({
      'Content-Type': 'application/json',
   });

   // "text/plain"
   console.log(res.get('Content-Type'));
   res.end();
});

app.listen(PORT, function(err){
   if (err) console.log(err);
   console.log("Server listening on PORT", PORT);
});

when hitting the end point the output :

application/json; charset=utf-8
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Express uses this method internally to check if particular headers are set, typically to set a default if they aren't or to augment them (for instance, in your example you set the Content-Type header to application/json, and Express appended ; charset=utf-8 to it).

You could imagine situations where a request handler wants to see if a particular middleware (perhaps a third-party one) set a particular header and/or a particular value, and adjust the way it handles the final response.

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