Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

317
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda