0

i am using Express & Ejs & body-parser ; Server js:

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

       if (!req.body) return res.sendStatus(400)
 console.log(req.body)

});

My Index.Ejs File

<div class="container">
                <fieldset>
                  <form action="/" method="post">
                    <input name="city" type="text" class="ghost-input" placeholder="Enter a City" required>
                    <input type="submit" class="ghost-button" value="Get Weather">
                  </form>                       
               </fieldset>
              </div>

i get this Error in console:-

Cannot set headers after they are sent to client
Prince Hamza
  • 700
  • 8
  • 19

1 Answers1

0

As I suggested in th comments, you should use the body-parser middleware for Express.

Eyal C
  • 1,442
  • 3
  • 24
  • 46