0
app.post('/templates/views/login', async(req,res) => {
    try {
      const em = req.body.email;
      const pass = req.body.pw;

      const useremail = await db.Register.findOne({
        email : em});
      
      if(useremail.pass === pw){
        res.status(201).render("index");
      }else {
        
      }

    } catch (error) {
      res.status(400).send("invalid email")
    }
  });  

this is the code which i am having error with not able to get data from mongodb and verify data it is always giving output of invalid email

Rits20
  • 1
  • 2
  • Do you have middleware to parse the request body? – jjroley Oct 14 '22 at 14:15
  • I am still learning so can you tell me exactly what is middleware :) – Rits20 Oct 14 '22 at 14:32
  • https://stackoverflow.com/questions/2904854/what-is-middleware-exactly There is a library called [body-parser](https://www.npmjs.com/package/body-parser) that you can use which will convert the json request body into a javascript object. – jjroley Oct 14 '22 at 15:57
  • oh I don't have any middleware to parse the request body – Rits20 Oct 14 '22 at 16:30

0 Answers0