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
  • 1,090
  • 12
  • 21

1 Answers1

0

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

Eyal
  • 1,649
  • 3
  • 25
  • 49