app.post('/reset', async (req, res) => { try{ //find a document with such email address const user = await User.findOne({email : req.body.email}) //check if user object is not empty if(user){ //generate hash const hash = new User(user).generatePasswordResetHash() //generate a password reset link const resetLink = `http://localhost:5000/reset?email=${user.email}?&hash=${hash}` //return reset link return res.status(200).json({ resetLink }) //remember to send a mail to the user }else{ //respond with an invalid email return res.status(400).json({ message : "Email Address is invalid" }) } }catch(err){ console.log(err) return res.status(500).json({ message : "Internal server error" }) } })