title: How to check if row exists in mysql, in Node js
body: <p>I would like to check in the record exists in mysql, I am working in Node js. My code is:</p>
  
  <pre><code>//Some code before where I get classes
  
  for (var m = 0; m &lt;= (classes.length-1); m++) {
      var Myurl = classes[m];
  
      (function(Myurl){
          var connection = mysql.createConnection({
              host: 'localhost',
              user: 'root',
              password: 'password',
              database: 'mydatabase',
          });
          connection.connect();
  
          //How do I write the query correctly?
          var query = connection.query('SELECT * FROM mydatabase WHERE UrlLink=? LIMIT 1', [Myurl], function(err, rows, fields) {
              if (err) 
                  throw err;
  
              SqlNames = rows;
              logNames();
  
              //If UrlLink is not present in mydatabase, then I want to proceed with:
              request(Myurl,  function(err, resp, body) {
                  // ...
              }
          });
  
          function logNames() {
              console.log(SqlNames);
          }
  
          connection.end();
      };
  })(Myurl);
  </code></pre>
  
  <p>So, I want to check if a record exists in my database, and if it does not exist I want to process with the request, and add it to the database. Now I get an error:</p>
  
  <blockquote>
    <p>connection is not defined</p>
  </blockquote>