title: Node.js Synchronous queries with MySQL
body: <p>I'm working on creating a user registration system for a website that I am working on but I am running into a few issues.</p>
  
  <p>I'm trying to stay away from having to nest callbacks because it gets kind of messy, What I need help with is finding if there is a way to create synchronous queries with node-mysql</p>
  
  <p>Here's what I'm trying to achieve.</p>
  
  <pre><code>connection.query("select 1 as email from users where email = " + connection.escape(email), function(err, rows, fields) {
      if(err) {
          var error = {
              error_message: err.code,
              error_number: err.errno
          };
  
          return res.send(error);
      }
  
      if(rows.length &gt; 0) {
          var error = {
              message: 'Email Address is Taken',
              code: 2
          };
          return res.send(error);
      }
  });
  
  connection.query("insert into users (email, password) values ("+connection.escape(email)+", "+connection.escape(hash)+")", function(err, rows, fields) {
              if(err) {
                  var error = {
                      error_message: err.code,
                      error_number: err.errno
                  };
  
                  return res.send(error);
              }
          });
  </code></pre>
  
  <p>My goal is to have the first query run and if that returns a row then to not execute the second query but if the first query returns 0 rows then continue and run the second query.</p>
  
  <p>I know I can nest the second query inside the first query and put if in an else but that's what I don't want to do because while I have those two queries I also have it set u to use bcrypt to encrypt the password which would have to be nested as well.</p>
  
  <p>Is there a way to write it so that I don't need to nest the two queries or is nesting them going to be my only option?</p>