fent / fent/node-ytdl-core

500 Internal Server Error When Streaming Audio from YouTube URL

Open
#1,304 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
4.7k
Forks
852
PR merge metrics
No merged PRs in 30d

Description

I have an endpoint that streams audio from a YouTube URL using ytdl-core. It works fine locally, but I encounter a 500 Internal Server Error on the server. Here's my code:
```
const express = require('express');
const ytdl = require('ytdl-core');

const app = express();

app.get('/audio', (req, res) => {
const videoUrl = req.query.url;

if (!videoUrl) {
return res.status(400).send('Video URL is required');
}

res.header('Content-Type', 'audio/mpeg');

ytdl(videoUrl, { filter: 'audioonly' })
.on('error', (err) => {
console.error('Error:', err);
res.status(500).send('Error streaming audio');
})
.pipe(res);
});

app.listen(3000, () => {
console.log('Server is running on port 3000');
});
```

Could someone help identify potential causes and solutions for this issue?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the reported Express /audio endpoint and its ytdl-core error log, then compare the server environment with the local setup. Reproduce the YouTube audio-only request on the server and identify the deployment-specific cause; done means the endpoint streams successfully without returning 500.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.