title: Javascript Node Read from CSV file and store data into object
body: <p>Trying to read a csv file and store data from it into an object which I can then use for other tasks. </p>
  
  <pre><code>    var csv = require('csv');
  
      var obj = csv();
  
      var filename = process.argv[2];
  
      function Employee(eno, ename, sal) {
  
          this.EmpNo = eno;
          this.EmpName = ename;
          this.Salary = sal;
      };
  
      var Employee = {};
  
      obj.from.path(filename).to.array(function (data) {
          for (var index = 0; index &lt; data.length; index++) {
                 Employees.push(new Employee(data[index][0], data[index][1], data[index][2]));
          }
      });
  
  console.log(Employee);
  </code></pre>
  
  <p>When running this I get the error: </p>
  
  <pre><code>var obj = csv();
            ^
  
  TypeError: csv is not a function
  </code></pre>
  
  <p>Any ideas?</p>
  
  <p>Edit: </p>
  
  <p>Changed to this as per answer below but cannot get the string to be populated outside the function:</p>
  
  <pre><code>string = {}
  
  var lineReader = require('readline').createInterface({
      input: fs.createReadStream(filename)
  });
  
  lineReader.on('line', function (line) {
      var splitLine = line.split(',');
  
          string[splitLine[0]] = {
              name: splitLine[0],
              dob: splitLine[1],
              employeeid: splitLine[2],
              country: domain,
              zone: splitLine[4],
              type: splitLine[5],
              id: splitLine[7],
              number: splitLine[8]
          }
  
      lineReader.close()
      }
  })
  
  console.log(string)
  </code></pre>