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

123
Vistas
Reading html form input with with node.js and express.js

I am trying to read the input from an HTML form and use it in Node.js.

This is my HTML form:

    <form action="/myform" method="POST">
        <input type="text" name="mytext" required />
        <input type="submit" value="Submit" />
    </form>

This is my Node.js code:


app.post('/myform', function(req, res){ 
  console.log(req.body.mytext); //mytext is the name of your input box
});

I am getting this error:

TypeError: Cannot read properties of undefined (reading 'mytext')
   

Please help me out.
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Make sure you are parsing the request. For that, add the line below at the top of your server root file:

app.use(express.urlencoded({
  extended: true
}));
about 4 years ago · Juan Pablo Isaza Denunciar

0

You have to used a inbuilt method express.json() for parsing json data. To used this method you need middlewares app.use()

So you have to defined it like below but before defining any routes in main file.

app.use(express.json())

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