title: node.js setInterval vs real time
body: <p>I am working on a tool that require to measure certain amount of time (for example 2 minutes) since user interaction with a tool, this time also needs to be displayed for the user.</p>
  
  <p>I started simple server loop for this reason:</p>
  
  <pre><code>setInterval(function() {
      measure.time();
  }, 10);
  </code></pre>
  
  <p>i created a code for to calculate:</p>
  
  <pre><code>this.reset = 0;
  this.step = 100 // 10 ms server loop, adds 1 to reset === 100 is 1 second
  this.time = function() {
      if(this.reset === this.step) {
          console.log('SPAWN', new Date());
          this.reset = 0;
      }
      this.reset++;
  };
  </code></pre>
  
  <p>this is the result of my approach:</p>
  
  <p><a href="https://i.stack.imgur.com/uabRv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uabRv.png" alt="enter image description here"></a></p>
  
  <p>The idea is to show clock for the user and update it every second, but it skips seconds rather often, what am i doing wrong?</p>