title: check if user name and email in database using expressJS
body: <p>I am trying to check if an email and an username in a database do already exist. Since I am using mongoose and express.js, I only checked if the username in a database already exists, but I need to check the email and username and return a suitable error message for each one. However, I don't know how to check them. Here are some of code that I wrote so far:</p>
  
  <pre><code>User.findOne({
              'username': username
          },
          function(err, user) {
  
              if (err) {
  
                  console.log('Signup error');
                  return done(err);
              }
  
              //if user found.
              if (user) {
  
                  console.log('Username already exists, username: ' + username);                                                             
                   var err = new Error();
                  err.status = 310;
                  return done(err);
  
              }
  </code></pre>