title: Making a simple registrarion/login using node.js and mysql
body: <p>Im trying to make a simple registration/login for a school project but i dont really know how to check if the user already exists in the database and send the response back to the client and inform the user that the username he is trying to use is already taken, this is the code i was using </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function confirm(username, email, password, callback) {
      var post = { username: username, email: email, password: password };
      var params = [post.username, post.email];
      var queryTest = global.connect.con.query('SELECT username, email FROM Utilizador WHERE username = ? AND email = ?', params, function(err, rows, fields) {
          console.log(rows);
          if (!err) {
              if (rows != "") {
                  console.log("user already exists");
              }
              else {
                  var query = global.connect.con.query('INSERT INTO Utilizador SET ?', post, function(err, rows, fields) {
                      console.log(query.sql);
                      if (!err) {
                          console.log("Number of records inserted: " + rows.affectedRows);
                      }
                      else
                          console.log('Error while performing Query.', err);
                  });
              }
          }
      });
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>instead of "console.log("user already exists");" i want to send an alert saying the same thing, but if i use an alert it does not work. obviously that isn't the only code i'm using but i'm not really sure what do i need to post here in order for anyone to understand my problem so if necessary i can post the rest.</p>