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

82
Vistas
Express POST request body outputting unidentified and {}

I am difficulty retrieving the body of an express post request form a HTML form. In my code I attempt to extract it normally raw and with JSON.stringify. Still no dice, just outputs:""Body: "undefined" received in app.js! ------- Body: "[object Object]" received in app.js!"" and the console outputs undefined and {}. Any help is appreciated. Bellow is both my JS code and HTML code.

const express = require('express');
const app = express();

const path = require('path');

const bodyParser = require('body-parser'); 
app.use(bodyParser.json()); 

app.use(express.urlencoded({
    extended: true
  }))

app.get('/', function(req, res) {
    res.sendFile(path.join(__dirname, './index.html'));
})

app.post('/submit-form', function(req, res) {

    var x = req.body.key;
    var y = req.body;

    console.log(x);
    console.log(y);

    console.log(JSON.stringify(x));
    console.log(JSON.stringify(y));
    
    res.send(`Body: "${x}" recieved in app.js! ------- Body: "${y}" recieved in app.js!`);

})

app.listen(4001, function() {
    console.log("Server is listening on port 4001...");
})
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Sample Site</title>

  <style>
    body { padding-top: 50px; }
  </style>
</head>
<body>

  <div class="container">
    <div class="jumbotron">
      <h1>res.sendFile() Works!</h1>
      
      <form method="POST" action="/submit-form", body= "key: 'hellow wolrd'"}>
        <input type="submit">
      </form>

    </div>
  </div>

</body>
</html>```
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The body of a POST request is determined by the values of the named form controls (input, select, etc elements) in the form.

There is no body attribute for the <form> element.

MDN has a forms + express tutorial that I recommend you read.

 <form method="POST" action="/submit-form">
     <input name=key value="hello, world">
     <button>Submit</button>
 </form>
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