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

316
Vistas
POST not working on Node.JS & Express

I'm trying to get user input from a html form but can't retrieve the data. This is the HTML code:

<form action="/login" method="POST" enctype="application/x-www-form-urlencoded">
    <div class="form-group">
        <label for="username">Username</label>
        <input type="text" class="form-control" id="username" placeholder="Username">
    </div>
    <div class="form-group">
        <label for="password">Password</label>
        <input type="password" class="form-control" id="password" placeholder="Password">
    </div>
    <button type="submit" class="btn btn-default">Login</button>
</form>

And here is the Node.JS code:

var bodyParser = require('body-parser'); 

var express = require('express');

var app = express();

app.use(bodyParser.json());

app.post('/login', function(req, res){
    console.log(req.body);
});

When I input data on the form, the post request returns {}. However, using Postman it works just fine...

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You need to use the bodyParser.urlencoded method to get it working.

Add the below snippet below your `app.use(bodyParser.json());' statement.

app.use(bodyParser.urlencoded({
     extended: true
})); 

Hope this helps!

about 4 years ago · Santiago Trujillo 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