Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

312
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!