title: Can I make nodejs --debug flag wait for a remote connection
body: <p>I would like to run the following script using <code>node --debug app.js</code> and have node wait for the remote debug session to start. I think the <code>app.js</code> script is crashing before the debugger can make a connection. I'm using a tunnel to forward port 5858 to a vagrant box and I know that part is working as I have used the exact same setup successfully before.</p>
  
  <p>Is this possible? The code is crashing at <code>afterCheck(err,spam)) //spam is not defined</code> and I want to figure out why.</p>
  
  <pre><code>var mysql      = require('mysql');
  var connection = mysql.createConnection({
      host     : 'localhost',
      user     : 'root',
      password : '123',
      database : 'kommunity',
      debug: ['ComQueryPacket']
  });
  
  var akismet = require('akismet').client({ blog: 'deleted', apiKey: 'deleted' });
  
  var selectPosts = "SELECT p.id as id, poster_ip, message, p.poster FROM topics  t\
                    LEFT JOIN posts p on t.first_post_id = p.id WHERE poster_ip != ''";
  
  //var spam = false;
  
  akismet.verifyKey(function(err, verified) {
      if(err) throw err;
      if (verified) {
  
          console.log('API key successfully verified.');
          connection.connect();
  
          connection.query(selectPosts, function(err, rows, fields) {
              if (err) throw err;
              var count = 0;
              rows.forEach( function(entry) {
  
              //console.log('foreach called with count '+count);
                  count++;
                  //console.log(entry['id']);
  
                  akismet.checkSpam({
                      user_ip: entry['poster_ip'],
                      comment_author: entry['poster'],
                      comment_content: entry['message']
  
                      }, afterCheck(err,spam))
  
                  });
          });
  
      }
  
      else {
  
          console.log('Unable to verify API key.');
      }
  
  });
  
  var afterDelete = function (err, rows, fields) {
  
      if (err) throw err;
      console.log('deleted topic '+rows[0]);
      console.log('spam');
      connection.end();
  
  }
  
  var afterCheck = function(err, spam, entry) {
  
      if(err) throw err;
  
  console.log('after check called and spam is :'+spam);
      var deleteQuery = "DELETE FROM topics , posts  USING topics INNER JOIN posts \
                         WHERE topics.id=posts.topic_id AND topics.id ="
      if(spam) {
          console.log('spam');
          console.log('entry is ' + entry);
          connection.query(deleteQuery + entry.id + ';', afterDelete(err, rows, fields) );
          connection.end();
  
      } else {
  
          console.log('Not spam');
  
      }
  }
  </code></pre>