title: Error: TypeError: Cannot read property 'catch' of undefined when trying to register user for website node.js
body: <p>I seem to have messed up one of my promises (I think) in a javascript function that is supposed to register a user. I have included the post request and the actual function itself.</p>
  
  <pre><code>app.post("/register", (req, res) =&gt; {
      dataServiceAuth.registerUser(req.body).then(() =&gt; {
          res.render("register", {successMessage: "User created"});
      }).catch((err) =&gt; {
          res.render("register", {errorMessage: err, user: req.body.user});
      });
  });
  
  
  
  module.exports.registerUser = function (userData) {
      return new Promise(function (resolve, reject) {
          if (userData.password != userData.password2) {
              reject("Passwords do not match");
          }
          else {
              let newUser = new User(userData);
  
              newUser.save((err) =&gt; {
                  resolve();
              }).catch((err) =&gt; {
                  if (err) {
                      if (err.code == 11000) {
                          reject('User Name already taken');
                      }
                      else {
                          reject('There was an error creating the user: ${err}');
                      }
                  }
              });
          }
      });
  };
  </code></pre>