title: Is there a way to know if a row exists in a mysql table using node.js?
body: <p>I'm trying to make a function that returns true if it detects a row containing a value in a specific column in nodejs.</p>
  
  <p>I've tried to use the result variable from query() without any success :</p>
  
  <pre><code>let rowexists = (mystring) =&gt; {
      let exists = false;
      let sql = "SELECT EXISTS( SELECT 1 FROM mytable WHERE `mycolumn` = '" + mystring + "')";
  
      connection.query(sql, function(error, result, field){
          console.log((result[sql]));
          console.log(exists);
          exists = (result[sql]);
      });
      return exists;
  }
  
  console.log(rowexists("myvalue"));
  </code></pre>
  
  <p>Event if there is a row with the value "myvalue" (there is), rowexists() always returns false.</p>
  
  <h3>IMPORTANT EDIT:</h3>
  
  <p>My problem isn't really the fact that this is async, it's the fact that both</p>
  
  <pre><code>console.log((result[sql]));
  </code></pre>
  
  <p>and</p>
  
  <pre><code>console.log(exists);
  </code></pre>
  
  <p>return undefined.</p>