title: Import a CSV into a JS variable in Node.js
body: <p>Trying to find the best method of importing and storing a CSV into a variable in Node.</p>
  <p>Currently the program was setup to compare against the data being entered in the js files manually however that's become to slow to update and a waste of time. But the idea is moving it to check a CSV file that they can update daily for the time being since this is done already.</p>
  <p>Data example below is what the program works with already:</p>
  <pre><code>var compareData = {
                &quot;20&quot;: {&quot;item&quot;: &quot;490583450-00&quot;, &quot;type&quot;: &quot;metal&quot;},
                &quot;26&quot;: {&quot;item&quot;: &quot;934793292-00&quot;, &quot;type&quot;: &quot;plastic&quot;}
                };
  </code></pre>
  <p>As for the CSV part, the CSV is your standard MS Excel CSV:</p>
  <blockquote>
  <p>ID,item,type</p>
  <p>20,490583450-00,metal</p>
  <p>26,934793292-00,plastic</p>
  </blockquote>
  <p>I can't get the variable to stick in some way to be used later. But I can see that its being parsed correctly with the following.</p>
  <pre><code>var fs = require('fs');
  var csv = require('csv');
  var iFile = fs.createReadStream('data.csv');
  parser = csv.parse({columns: true, 'objname': &quot;ID&quot;},function(err, data){
      console.log(data);
  })
  iFile.pipe(parser);
  </code></pre>