title: Convert CSV-stream to UTF-8 in Node.js
body: <p>In advance I have to say I'm new to <strong>node.js</strong> and may did not understand it fully yet.</p>
  
  <p>I'm stuck at the moment with a rather obvious problem that I can't solve. I am importing a CSV file from a FTP server via the node module "<a href="https://www.npmjs.com/package/ftp" rel="nofollow noreferrer">ftp</a>"
  then I'm receiving the file as a stream which I then convert to a JSON with the node module "<a href="https://www.npmjs.com/package/csvtojson" rel="nofollow noreferrer">csvtojson</a>".</p>
  
  <p>So far that works wonderfully. But now I noticed that I stumbled over some <strong>Umlaut</strong> chars from the German language which keep crashing my solution. I found out that I have to convert the file stream to UTF8, but I have no idea how. </p>
  
  <p>I tried it already with the <code>toString()</code> method and several other node modules but that also didn't work.</p>
  
  <p>My code looks like this:</p>
  
  <pre><code>getCsvFromFtp: function (profile) {
      init(profile);
      return new Promise((resolve, reject) =&gt; {
          client.on('ready', function () {
              client.get(file, function (err, stream) {
                  if (err) {
                      return reject(err);
                  }
                  stream.once('close', () =&gt; {
                      client.end();
                  });
                  csv({
                      trim: true,
                      delimiter: delimiter,
                  }).fromStream(stream, (err, result) =&gt; {
                      if (err) {
                          return reject(err);
                      }
                      return resolve(csvFormatterService.groupAndFormatOrders(result));
                  });
              });
          });
          client.connect(ftpCredentials);
      });
  }
  </code></pre>
  
  <p><strong>EDIT:</strong>
  I found out that the problem was not my code, but the encoding of the file. the file was Western (ISO 8859-1) encoded.</p>