A simple Node.js script that downloads videos and converts them to MP3 files using yt-dlp.
- Downloads single YouTube videos or entire playlists
- Automatically converts videos to MP3 format
- Uses video title as filename
- Best audio quality
- URL validation
- Node.js (v14 or higher)
- yt-dlp - Installation instructions
Windows:
# Using winget
winget install yt-dlp
# Or using scoop
scoop install yt-dlpmacOS:
brew install yt-dlpLinux:
# Using pip
pip install yt-dlp
# Or download binary
sudo curl -L https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -o /usr/local/bin/yt-dlp
sudo chmod a+rx /usr/local/bin/yt-dlp- Clone or download this repository
- Install dependencies:
npm installRun the script:
npm startOr directly with node:
node index.js- Minimal dependencies (only
promptsfor CLI input) - Uses
yt-dlpvia Node.jschild_process
Problem: The script cannot find the yt-dlp executable.
Solutions:
- Windows: Run
install.batand choose option 2 or 3 to install yt-dlp via winget - Manual installation:
- Verify yt-dlp is installed:
yt-dlp --version - If not installed, follow the installation instructions above
- If installed but not found, add yt-dlp to your system PATH
- Restart your terminal/command prompt after installation
- Verify yt-dlp is installed:
Problem: Node.js is not available on your system.
Solutions:
- Download and install Node.js from nodejs.org
- Verify installation:
node --version - Restart your terminal after installation
- Windows: Run
install.batwhich will guide you through the installation
Problem: Dependencies could not be installed.
Solutions:
- Check your internet connection
- Try running as administrator (Windows) or with sudo (Linux/macOS)
- Delete the
node_modulesfolder andpackage-lock.json, then runnpm installagain - Clear npm cache:
npm cache clean --force - Update npm:
npm install -g npm@latest
Problem: yt-dlp cannot download the video.
Solutions:
- Update yt-dlp to the latest version:
yt-dlp -U(or runinstall.batoption 2) - Check if the video is available and not region-blocked
- Try a different video URL to verify it's not a general connectivity issue
- Some videos may be protected - try a different source
Problem: Required npm package is missing.
Solutions:
- Run
npm installin the project directory - Windows: Run
install.batand choose option 1 or 3 - If error persists, delete the
node_modulesfolder and runnpm installagain
Problem: Downloaded audio quality is not as expected.
Solution:
- The script uses
--audio-quality 0which means best quality - But audio quality depends on the source video quality and some videos may not have high-quality audio streams available
Problem: Downloads fail on Windows due to invalid characters in video titles.
Solutions:
- yt-dlp handles most special characters automatically
- If issues persist, the video title may contain characters Windows doesn't support
- Try downloading to a different location with a shorter path
Problem: yt-dlp was installed but the terminal cannot find it.
Solutions:
- Windows: Close and reopen your command prompt/terminal
- The PATH may not be updated in the current session
- Log out and log back in to refresh environment variables
- Manually verify installation location and add to PATH if needed