title: Node JS setInterval. TypeError: Cannot read property 'apply' of undefined
body: <p>I am Nowfal, a c# programmer. I am new in Node JS.
  When I create a function and gave inside setInterval an error occured as 
  TypeError: Cannot read Property 'apply' of undefined </p>
  
  <p>at wrapper [as _onTimeout] (timers.js:274:13)</p>
  
  <p>at Timer.listOnTimeout (timers.js:119:15)</p>
  
  <p>My code  pages are given below</p>
  
  <p><strong>Page 1(Server.js)</strong></p>
  
  <pre><code>var db = require('./dbConnect.js');
  var ins = require('./dbInsert.js');
  
  var tagId = [];
  var schoolInfoId = [];
  var imeNo = [];
  var totalRows = 0;
  
  function ViewQuery() {
      var mysql = db.mysql;
      var connection = db.createMyConnection();
  
  
      connection.connect();
  
  
      var mycommand = "SELECT     t.skha_tag_id_no,s.skha_school_info_id,a.skha_out_device_imeno" +
          " FROM skha_tag t INNER JOIN skha_student_info s on skha_tag_id     = skha_student_tag_id_no " +
           " INNER JOIN skha_student_school_attendance a on     a.skha_student_info_id = s.skha_student_info_id" +
           " WHERE DATE(skha_student_in_time) = CURDATE() AND     skha_student_out_time IS NULL and skha_out_status = 1 ";
  
       connection.query(mycommand, function (err, rows) {
          if (!err) {
  
           var result;
              for (i = 0; i &lt; rows.length; i++) {
                  totalRows++;
  
                  result = rows[i];
  
                  tagId.push(result['skha_tag_id_no']);
                  schoolInfoId.push(result['skha_school_info_id']);
                  imeNo.push(result['skha_out_device_imeno']);
  
              }
  
  
              for (i = 0; i &lt; totalRows; i++) {
                  ins.insertDB(tagId[i], schoolInfoId[i], imeNo[i]);
              }
  
          }
          else
              console.log('Error while performing Query.');
      });
  
      connection.end();
  
  };
  
  setInterval(ViewQuery(),30000); //Error Generating from here
  </code></pre>
  
  <p><strong>Page 2(dbConnect.js)</strong></p>
  
  <pre><code>var mysql = require('mysql');
  
  exports.createMyConnection = function createMyConnection() {
      var connection = mysql.createConnection( {
          host    : '192.168.0.175',
          user    : 'ss_user',
          password : 'df33-ccff2188',
          database : 'shkaliasdb',
          multipleStatements: true
      });
      return connection;
  }
  
  exports.mysql = mysql;
  </code></pre>
  
  <p><strong>Page 3 (dbInsert.js)</strong></p>
  
  <pre><code>var db = require('./dbConnect.js');
  
  var logOutTimeInterval = 5;
  exports.insertDB = function (RFID, schoolID, imei) {
  
      var mysql = db.mysql;
      var connection = db.createMyConnection();
  
      connection.connect();
      console.log('IMEI : ' + imei);
      console.log(RFID);
  
  
  
      str = "SET @OutStatus=0;SET @logOutTime=0;call     out_mark_save_two_device('" + RFID + "'," + schoolID + "," +      logOutTimeInterval + ",@OutStatus,@logOutTime," + imei + ")";
  
      console.log(str);
  
  
      connection.query(str, function (err, rows, fields) {//, fields
          if (err)
              console.log('Error while performing Query.' + err);
           else {
              console.log(rows[0]);
  
          }
      });
  
      connection.end();
  
  
  };
  </code></pre>
  
  <p>First time code works correctly and then shows error message, timer not working.</p>
  
  <p>Please give me any solution for this...
  Thanks in Advance..</p>