title: Implementing forgot password feature, Search and if email exists, send email Node.JS does not work as Expected
body: <p>i want to do something like when a user searches a mongoDB Database, and user exists it should then send an email to the user with a password Reset link. For some reason it does not work as expected.
  it just goes ahead to send emails, And does not check if the email exists , i dont know why it behaves so.</p>
  <p>My code looks like this :</p>
  <pre><code>exports.forgot_pass = function(req,res,next){
  
      User.findOne({
          user_email : req.body.user_email
      }).exec((err,user)=&gt;{
          if(err){
              res.status(500).send({message : err});
              return;
          }
          if(!user){
              res.status(400).send({message: &quot;Sorry Email does not Exist!&quot;});
          }else{
              var user_email = req.body.user_email;
              const transporter = nodemailer.createTransport({
                  service:'gmail',
                  host: 'smtp.gmail.com',
                  port:'587',
                  auth:{
                      user: '**************@gmail.com',
                      pass: '***********'
                  },
                  secureConnection: 'false',
                  tls: {
                      ciphers: 'SSLv3',
                      rejectUnauthorized: false
                  }
              });
              const mailOptions = {
                  from :'***********@gmail.com',
                  to: user_email,
                  subject: 'Please Reset your Password',
                  html : '&lt;h3&gt;Dear User&lt;/h3&gt;&lt;p&gt;You have requested to Reset your password. To Reset your password Successfully, Follow the Link bellow to Reset it&lt;/p&gt;&lt;p&gt;Click &lt;a href=&quot;https://**********/user/resetPassword.jsp&quot;&gt;https://onepercentsoft.oxygen.com/user/resetPassword.jsp&lt;/a&gt;&lt;/p&gt;&lt;p&gt;This Email is subject to mandatory instruction.&lt;/p&gt;&lt;p&gt;Regards,&lt;/p&gt;&lt;p&gt;Online Service&lt;/p&gt;'
              };
          
              transporter.sendMail(mailOptions,function(error,info){
                  if(error)throw error;
                  return res.send({error:false, data: info, message: 'OK'});
              })
          }
      });
  
  };
  </code></pre>
  <p>But this does not check for anything, It just goes ahead and sends the email. I need help here.</p>