The downloaded MP3 lacks ID3 tags (artist, title, album, cover art). You would need additional libraries like node-id3 to add metadata after download.
That's it! You've successfully created a YouTube MP3 downloader using Node.js and the youtube-mp3-downloader NPM package.
In this tutorial, we will build a simple command-line application that allows users to download MP3 files from YouTube videos using the youtube-mp3-downloader NPM package.
// Event: when download finishes successfully YD.on("finished", (err, data) => if (err) return console.error(err); console.log( MP3 saved to: $data.file ); ); youtube-mp3-downloader npm
| Package Name | How It Works | Key Features | Pros | Cons | | :--- | :--- | :--- | :--- | :--- | | | Downloads the video stream, then uses FFmpeg to transcode the audio to MP3 and save it to disk. | - Parallel downloads ( queueParallelism ) - User-defined output path - Progress events | - Simple and proven - Good for basic needs - Detailed progress | - Requires separate FFmpeg install - Development appears inactive | | yt-mp3-converter | Uses ytdl-core for downloading and fluent-ffmpeg for the conversion to MP3. | - Easy-to-use API - Can generate an HTML download button for web apps - Lightweight | - Simple and focused - Well-documented | - Relies on ytdl-core (which may be less reliable than yt-dlp ) | | new-youtube-exec | A wrapper for youtube-dl-exec , which calls the very powerful yt-dlp command-line tool. | - Very simple API - Built on yt-dlp , known for its reliability and speed - Can handle many streaming sites, not just YouTube | - Fast and reliable - Low-level complexity hidden | - Still requires the yt-dlp binary on your system | | yt-finder-nextgen | A modern TypeScript library that includes both search functionality for YouTube and the ability to download as MP3 or MP4. | - Search for videos - Downloads as MP3 - Supports both CommonJS and ESM | - All-in-one search and download - TypeScript support | - Lower weekly downloads, community unknown | | ytsave | A library and CLI tool that uses yt-dlp as its engine. It is designed for single videos and entire playlists and offers a very straightforward approach. | - Audio-only (mp3) and video (mp4) formats - Download entire playlists - Works as a CLI tool or Node.js library | - Very easy to use - Great for downloading a lot of music | - Requires yt-dlp and ffmpeg installed separately |
const ytdl = require('ytdl-core'); const videoUrl = 'https://youtube.com...'; ytdl.getInfo(videoUrl).then(info => Downloader.download(info.videoDetails.videoId); ); Use code with caution. Best Practices and Troubleshooting 1. ytdl-core Limitations
A wrapper around the Python tool yt-dlp (a fork of youtube-dl ). yt-dlp is far more robust against YouTube's changes and is updated almost daily. The downloaded MP3 lacks ID3 tags (artist, title,
const YouTubeMp3Downloader = require('youtube-mp3-downloader');
function extractId(url) youtu.be/)([a-zA-Z0-9_-]11)/); return match ? match[1] : null;
// Configure downloader const YD = new YoutubeMp3Downloader( outputPath: DOWNLOAD_DIR, youtubeVideoQuality: "highest", queueParallelism: 1, progressTimeout: 1000 ); You've successfully created a YouTube MP3 downloader using
youtube-mp3-downloader is an open-source npm package designed for Node.js environments. It acts as a wrapper around two essential tools: Downloads the YouTube video stream.
Unlike pure-JS solutions, your runtime environment must have FFmpeg installed. This makes deployment to serverless platforms (AWS Lambda, Vercel) more complex unless you bundle a static FFmpeg binary.
Create a new instance of the YouTubeMP3Downloader class, passing in the path where you want to save the downloaded MP3 files:
Integrating this package into a Node.js project is straightforward, typically requiring only a few lines of configuration. Once initialized with the path to the system's FFmpeg binary