How do I download only audio from youtube using ytdl-core with javascript

Viewed 40

Here is the code that I'm using.

var express = require('express');
var app = express();
var ytdl = require('ytdl-core');
const fs = require('fs');

app.listen('4000', function(){
    console.log("listening on 4000");
});

app.get('/download', function(req, res) {
    var link = req.query.url;
    var format = req.query.format;

    
    const video = ytdl(link, format, { quality: 'audioonly'});
    
    video.pipe(fs.createWriteStream(res))

});

I am trying to make a website to download youtube videos as mp4 and mp3 this is just a script so I knw how to do the mp3 part.

0 Answers
Related