title: Node js : change csv file encoding programatically and parse to json
body: <p>I have a csv file with <code>utf-16</code> encoding, and need to change its enconding to <code>utf8</code> and convert it to JSON. I'm using <code>csvtojson</code> and <code>iconv-lite</code> modules. Here is my code: </p>
  
  <pre><code>var data = fs.createReadStream("myfile.csv");
  data.pipe(iconv.decodeStream('utf16'))
    .pipe(iconv.encodeStream('utf8'))
    .pipe(fs.createWriteStream("encoded.csv"));
  var Converter = require("csvtojson").Converter;
  var csvStr = fs.readFileSync("encoded.csv").toString();
  var converter = new Converter({});
  converter.fromString(csvStr, function(err, jsonObj) {
      if (err) {
          handleError(err)
      }
      console.log(jsonObj)
  });
  </code></pre>
  
  <p>The problem is that <code>iconv</code> converts the csv file with the right encoding, but when I read this file and call <code>toString()</code> method, it returns an empty string. How can I fix this?</p>