title: When I'm making a POST requestion in my login page
body: <p>I'm getting this error: <code>Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client</code> when I'm running my ExpressJS code.</p>
  <p>Please help guys, this is my first question on stackoverflow btw and I don't really know how to ask questions :^)</p>
  <p>My code:</p>
  <pre><code>app.route(&quot;/&quot;)
  
  .get(function(req,res){
      res.render(&quot;home&quot;);
  })
  
  app.route(&quot;/register&quot;)
  .get(function(req,res){
      res.render(&quot;register&quot;);
  })
  
  .post(function(req,res){
  
      bcrypt.hash(req.body.password, saltRounds, function(err, hash) {
          const newUser = new User({
              email: req.body.username,
              password: hash
          })
      
          newUser.save(function(err){
              if (err){
                  console.log(err);
              } else {
                  res.render(&quot;secrets&quot;);
              }
          });
      });
  });
  
  app.route(&quot;/login&quot;)
  .get(function(req,res){
      res.render(&quot;login&quot;);
  })
  
  .post(function(req,res){
      const username = req.body.username;
      const password = req.body.password;
  
      User.findOne({email: username}, function(err, foundUser){
          if (err){
              console.log(err);
          } else {
              if (foundUser){
                  bcrypt.compare(password, foundUser.password, function(err,result){
                      if (result === true){
                          res.render(&quot;secrets&quot;);
                      }
                  });
              }
          }
      });
      
  });
  
  app.listen(3000, function(){
      console.log(&quot;Server started...&quot;);
  });
  </code></pre>
  <p>I got this error after I made a <code>POST</code> request in my login page, it was stuck on loading and It wasn't loading the <code>secrets.ejs</code> page. I think the error is in the <code>login</code> route, 'cause I'm getting that error when I'm making a <code>POST</code> request in login route.</p>