I am making a simple website for my grandad so he can download videos from YouTube. To do this, I am using an npm package (ytdl-core), MERN stack, and Heroku.
I have the following code (which it works locally on my computer):
app.post("/download", (req, res) => {
const { searchBar } = req.body;
const address = searchBar;
console.log(address);
const option = Object.keys(req.body)[1];
console.log(option);
let id = address.slice(32);
if (option === "video") {
ytdl(address).pipe(fs.createWriteStream('video.mp4'));
console.log("Downloading!");
}
res.redirect("/");
});
How it works: the user (my grandad) pastes the URL of the video into a form with two options (video or audio) and then the code above handles the rest.
Problem: the file is never downloaded.
Remember: it works locally, but as soon as I try it using Heroku it doesn't download anything.