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

195
Vistas
How to access variables within a post request?

I'm just starting to learn about HTTP post methods and would like to know if it is possible to get access to variables within the method so that I can export/use it.

Here is my code:

var word = [];
app.post("/search", (req, res) => {;
      console.log(req.body)
      word = req.body["searchedWord"]
    });
console.log(word)

FYI: The req i get looks like { searchedWord: 'soda' }

It currently returns "undefined". If I were to have the console.log(word) within the method, what I want is returned. Any help/tips will be appreciated! Thank you!

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

0

it looks like you are getting responses in JSON format so you have to do like this

const text = '{"name":"John", "birth":"1986-12-14", "city":"New York"}';
const obj = JSON.parse(text);
obj.birth = new Date(obj.birth);

document.getElementById("demo").innerHTML = obj.name + ", " + obj.birth;


instead of it 
 word = req.body["searchedWord"]
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