title: Node.js Stream Mp3 to http without having to save file
body: <p>I am trying to stream just audio from a youtube link straight to http with node.js.</p>
  
  <p>My code looks like this, I am using express 4.0.</p>
  
  <pre><code>var express = require('express');
  var router = express.Router();
  var ytdl = require('ytdl');
  var ffmpeg = require('fluent-ffmpeg');
  var fs = require('fs');
  
  router.get('/', function(req, res) {
  
    var url = 'https://www.youtube.com/watch?v=GgcHlZsOgQo';
    var video = ytdl(url)
  
    res.set({
        "Content-Type": "audio/mpeg"
    })
  
    new ffmpeg({source: video})
        .toFormat('mp3')
        .writeToStream(res, function(data, err) {
          if (err) console.log(err)
        })
  
  });
  
  module.exports = router;
  </code></pre>
  
  <p>Now, I'm able to stream the video's audio to the response if I save the file then pipe it to the response, but I'd rather try to figure out some way to go from downloading to ffmpeg to response.  </p>
  
  <p>Not sure if this is possible.  The main goal is to keep it as light weight as possible, and not have to read from files.</p>
  
  <p>I've seen <a href="https://stackoverflow.com/questions/18168432/node-js-how-to-pipe-youtube-to-mp4-to-mp3">this</a> code which is essentially what I'd like to do minus the saving to a file part.</p>
  
  <p><img src="https://i.stack.imgur.com/FVO0k.png" alt="part of the error"></p>