I was testing my app on localhost and everything seemed to work correctly, but then I pushed my website to azure websites and things were working there as well except when I create a user it throws 500 error I don't get what could be the possible reason. here is my route for creating users

router.post('/create', admin, (req, res, next) => {
  bcrypt.hash(req.body.password, 10).then(hash => {
    const user = new User({
      email: req.body.email,
      username: req.body.username,
      userType: req.body.userType,
      company: req.body.company
    });

    User.countDocuments({
        email: req.body.email
      })
      .then(count => {
        if (!count) {
          user.save()
            .then(result => {
              res.status(201).json({
                message: 'User created!',
                result: result
              });
            })
            .catch(err => {
              res.status(500).json({
                error: err
              });
            });
        } else {
          res.status(500).json({
            message: 'Email already exists!'
          });
        }
      })
      .catch(err => {
        res.status(500).json({
          error: err,
          message: 'Email already exists!'
        });
      });
  });
});

so whenever I test the app on angular it shows email already exists! and 500 error

0 Answers