I cannot tell if you're asking about downloading a youtube video as an mp3 using node - but this thread popped up on top of google when I was researching just that. So, if not, perhaps it can point you in the right direction or help someone in the future... Mods - sorry if I'm not doing this right.
Additional StackOverflow Reference
But I am using the following code to do download a youtube vid as mp3 (download youtube vid / convert to mp3 / download) :
module.exports.toMp3 = function(req, res, next){
var id = req.params.id; // extra param from front end
var title = req.params.title; // extra param from front end
var url = 'https://www.youtube.com/watch?v=' + id;
var stream = youtubedl(url); //include youtbedl ... var youtubedl = require('ytdl');
//set response headers
res.setHeader('Content-disposition', 'attachment; filename=' + title + '.mp3');
res.setHeader('Content-type', 'audio/mpeg');
//set stream for conversion
var proc = new ffmpeg({source: stream});
//currently have ffmpeg stored directly on the server, and ffmpegLocation is the path to its location... perhaps not ideal, but what I'm currently settled on. And then sending output directly to response.
proc.setFfmpegPath(ffmpegLocation);
proc.withAudioCodec('libmp3lame')
.toFormat('mp3')
.output(res)
.run();
proc.on('end', function() {
console.log('finished');
});
};