title: How can I calculate the difference between each subsequent line of a text file using JavaScript?
body: <p>I have two feed bins (BinA, BinB) that output data via XML. Using Node, I can already successfully parse and log the relevant data to a text file every 5 minutes, see snippet:</p>
  
  <pre><code>(timestamp),(BinA current weight),(BinB current weight)
  
  2020-06-16 13:49,4874,5578
  2020-06-16 13:54,4871,5574
  2020-06-16 13:59,4870,5573
  </code></pre>
  
  <p>Now, I want to calculate the "usage" every 5 minutes (between every line) and save it into another array. Subtracting the line below from the line above consecutively (4874-4871 = 3, 5578-5574 = 4,...) should result in this array:</p>
  
  <pre><code>(timestamp),(BinA minus line above),(BinB minus line above)
  2020-06-16 13:54,3,4
  2020-06-16 13:59,1,1
  </code></pre>
  
  <p>which is simple to load into a charts.js graph, and also generate alerts for over and under usage. </p>
  
  <p>So far I'm getting nowhere with loops trying to come up with this data, and I haven't been able to find a similar problem/solution elsewhere.</p>
  
  <p>Files for those interested (xml, data1.txt, app.js: 
  [<a href="https://www.dropbox.com/sh/q6z7735bhy2k7fh/AACaai717meRVvzxj9LxVBLda?dl=0][1]" rel="nofollow noreferrer">https://www.dropbox.com/sh/q6z7735bhy2k7fh/AACaai717meRVvzxj9LxVBLda?dl=0][1]</a></p>
  
  <p>Btw, this is my first Node/Javascript project! (inspired by a problematic chicken barn)</p>