While many npm packages exist (like ytdl-core ), they often break when YouTube updates their internal code. The most robust method currently is to use a Node.js wrapper for (a powerful command-line tool) combined with ffmpeg to handle the audio conversion.
You need two things installed on your system (not just npm): youtube-mp3 downloader npm