title: Node: Hit endpoint that returns a CSV file and send the contents to client
body: <p>I'm given an endpoint that returns a CSV file. I want to hit that end point, read the data, and send it to the client. This is what I have right now.</p>
  
  <pre><code>app.get('/data', (req, res) =&gt; {
    request('foo.com/downloadCSV', (error, response, body) =&gt; {
      res.send(csvToJson(body));
    });
  });
  </code></pre>
  
  <p>So on the front end, I hit '/data', which then uses the request library to make the call to get the CSV data. The body for the CSV is in 'body'. The 'csvToJson' function just formats the data given into arrays/json.</p>
  
  <p>When I console.log the response on my client, my body is: ReadableStream, locked(...)</p>
  
  <p>How do I get the data to the client?</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>Here is my csvToJson function:</p>
  
  <pre><code>const csvToJson = (csv) =&gt; {
    const content = csv.split('\r');
    const header = content[0].split(',');
    return _.tail(content).map((row) =&gt; {
      return _.zipObject(header, row.split(','));
    });
  }
  </code></pre>