0
 User.findOne({ email: req.body.email }).then((user) => {  
    var result = {};
    if (!user) {
       result.message = "Not Found"
       return res.status(404).send(result);
    }
    //check password matches
    if (user.password == req.body.password) {
        user.status = "Success";
        result.message = "Success"
        res.status(200).send(user);
    } else {
        result.message = "Invalid Password";
        res.status(404).send(result);
    }
  })
    .catch((err) => {
        res.status(500).send(err);
    });
});

How can I convert from text to json the above code. I am checking in postman and it is not accepting the user when checking on text.

Suyash Mittal
  • 73
  • 1
  • 13
pratibha
  • 85
  • 2
  • 10
  • use [JSON.parse](https://www.w3schools.com/js/js_json_parse.asp) – flix Feb 06 '19 at 07:35
  • 2
    Possible duplicate of [In Node.js, how do I turn a string to a json?](https://stackoverflow.com/questions/5801699/in-node-js-how-do-i-turn-a-string-to-a-json) – Suyash Mittal Feb 06 '19 at 07:44
  • User.findOne({ email: req.body.email }).then((user) => { var json = 'user', obj = JSON.parse(json); var result = {}; if (!obj) { result.message = "Not Found" return res.status(404).send(result); } //check password matches if (obj.password == req.body.password) { user.status = "Success"; result.message = "Success" res.status(200).send(user); } }) i have tried this way but still getting message:not found – pratibha Feb 06 '19 at 07:58

0 Answers0