npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

ytdl-lite

v1.0.1

Published

Zero-dependency YouTube downloader & search — MP3/MP4 links, quality selection, file saving, CLI. Works with CommonJS and ESM.

Downloads

778

Readme

npm downloads node types deps license

Fast, zero-dependency YouTube downloader, search & metadata toolkit for Node.js. MP3 · MP4 · Playlists · Full video details · CLI · CommonJS + ESM + TypeScript

Install · Quick start · API · CLI · Recipes · FAQ

✨ Why ytdl-lite?

| | | |---|---| | 🪶 Zero dependencies | Built on Node 18+ fetch. Nothing to audit, tiny install. | | 🔀 Dual package | require() and import both work, with bundled TypeScript types. | | 🔎 URL or search text | ytmp3('believer') works as well as ytmp3(url). | | 🛡️ Self-healing search | Innertube → Piped → Invidious → HTML, automatic fallback + 30 min cache. | | 📊 Rich metadata | Description, views, likes, dates, keywords, chapters, channel, thumbnails. | | 📃 Playlists | Full details and every video, with automatic pagination. | | 💾 Save to disk | { save: true } streams the file with live progress callbacks. | | 🧰 CLI included | ytdl mp3 / mp4 / search / info / playlist. | | 🧯 Typed errors | YTDLError with stable .code values you can branch on. |

📦 Install

npm  install ytdl-lite
pnpm add     ytdl-lite
yarn add     ytdl-lite
bun  add     ytdl-lite

Requires Node.js ≥ 18.

🚀 Quick start

const { ytmp3, ytmp4, search,
        getInfo, getPlaylist } = require('ytdl-lite');
import { ytmp3, ytmp4, search,
         getInfo, getPlaylist } from 'ytdl-lite';
const URL = 'https://youtu.be/dQw4w9WgXcQ';

// 🎵 MP3 — from a link or plain text
const song = await ytmp3(URL);
const same = await ytmp3('never gonna give you up');
console.log(song.url, song.path);        // direct link + suggested filename

// 💾 …and save it to disk with progress
await ytmp3(URL, 'best', {
  save: true,
  dir: './music',
  onProgress: p => p.percent && console.log(`${p.percent}%`)
});

// 🎬 MP4 — pick a quality, or get them all
await ytmp4(URL, '720');                 // 360 | 480 | 720 | 1080 | best | worst
const all = await ytmp4(URL, null);      // every format -> all.medias[]

// 🔎 Search
const results = await search('believer', { limit: 5 });

// 📊 Everything about a video
const info = await getInfo(URL);
console.log(info.title, info.views, info.likes, info.chapters);

// 📃 Playlists
const pl = await getPlaylist('https://youtube.com/playlist?list=PL…', { all: true });
console.log(`${pl.title} — ${pl.videoCount} videos`);

📚 API reference

input is a YouTube URL or a search query. The service returns one best-quality MP3 (quality is kept for backward compatibility).

{
  "status": true,
  "id": "dQw4w9WgXcQ",
  "title": "Rick Astley - Never Gonna Give You Up (Official Video)",
  "author": "Rick Astley",
  "duration": "3:33",
  "thumbnail": "https://i.ytimg.com/vi/dQw4w9WgXcQ/hqdefault.jpg",
  "url": "https://…/audio.mp3",
  "quality": "best",
  "type": "audio",
  "path": "./rick-astley-never-gonna-give-you-up-official-video.mp3",
  "file": "/abs/path.mp3",   // only with save: true
  "size": 3563412           // only with save: true
}

| quality | Result | |---|---| | '360' '480' '720' '1080' (also '720p') | exactly that quality | | 'best' | tries 1080 → 720 → 480 → 360 until one works | | 'worst' | tries 360 → 480 → 720 → 1080 | | null | all formats in parallel → { medias: [{ type, quality, label, url, path }] } |

{
  "id": "dQw4w9WgXcQ", "url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
  "title": "…", "description": "…",
  "author": "Rick Astley", "channelId": "UC…", "channelUrl": "https://www.youtube.com/channel/UC…",
  "duration": "3:33", "seconds": 213,
  "views": 1500000000,
  "likes": 18000000,                  // best effort — may be null
  "publishDate": "2009-10-25", "uploadDate": "2009-10-24",
  "category": "Music", "keywords": ["rick astley", "…"],
  "chapters": [{ "time": "0:00", "seconds": 0, "title": "Intro" }],
  "isLive": false, "isPrivate": false, "isUnlisted": false, "isFamilySafe": true,
  "availableCountries": ["US", "GB", "…"],
  "playlistId": null,
  "thumbnail": "…", "thumbnails": { "default": "…", "medium": "…", "high": "…", "standard": "…", "maxres": "…" },
  "thumbnailList": [{ "url": "…", "width": 336, "height": 188 }]
}

If YouTube blocks the detailed lookup you get the basic fields with partial: true instead of an error. Pass { likes: false } to skip the extra like-count request.

{
  "id": "PL…", "url": "https://www.youtube.com/playlist?list=PL…",
  "title": "…", "description": "…",
  "author": "…", "channelId": "UC…", "channelUrl": "…",
  "videoCount": 42, "views": 120000, "lastUpdated": "Oct 3, 2025",
  "totalSeconds": 9660, "thumbnail": "…", "hasMore": false,
  "items": [
    { "index": 1, "id": "…", "url": "…", "title": "…", "author": "…",
      "duration": "3:33", "seconds": 213, "thumbnail": "…", "isPlayable": true }
  ]
}

all: true follows every continuation page (capped at 5000 videos).

Returns { id, url, title, author, duration, seconds, views, thumbnail }[]. Restrict or reorder engines with providers: ['innertube', 'piped', 'invidious', 'html'].

| Function | Purpose | |---|---| | getLink(url, format, opts?) | Direct link for mp3 / 360 / 480 / 720 / 1080 | | saveFile(url, path, { onProgress }) | Stream any URL to disk | | resolve(input) | URL or query → single video | | extractVideoId(url) · extractPlaylistId(url) · isYouTubeUrl(url) | URL parsing | | slugify(title) · buildPath(title, ext, dir) | Unicode-safe filenames | | parseChapters(description) | Chapters from timestamps | | formatDuration(sec) · parseDuration('1:02:05') · formatBytes(n) | Formatting | | thumbnails(id) | All thumbnail sizes | | clearSearchCache() | Flush the search cache |

⚙️ Common options

| Option | Default | Description | |---|---|---| | dir | './' | Directory for the suggested / saved path | | save | false | Download the file to disk | | onProgress | – | ({ stage, percent, downloaded, total }) => void | | apiKey | env YTDL_API_KEY | Override the converter key | | timeout | 20000 | Per-request timeout (ms) | | maxWaitMs | 120000 | Max time to wait for conversion | | retries | 2 | Start-request retries |

🧯 Error codes

import { YTDLError } from 'ytdl-lite';

try { await ytmp4(URL, '720'); }
catch (e) {
  if (e instanceof YTDLError && e.code === 'TIMEOUT') { /* retry later */ }
}

| Code | Meaning | |---|---| | INVALID_INPUT · INVALID_URL · INVALID_QUALITY | Bad arguments (thrown before any network call) | | SEARCH_FAILED · NO_FORMATS · NO_RESULTS | Nothing found | | VIDEO_UNAVAILABLE · PLAYLIST_UNAVAILABLE | Private / removed / region-blocked | | TIMEOUT · NETWORK · HTTP_ERROR · BAD_RESPONSE | Transport problems |

🖥️ CLI

npm i -g ytdl-lite        # or: npx ytdl-lite …

| Command | Example | |---|---| | ytdl mp3 <url\|query> | ytdl mp3 "never gonna give you up" --save --dir ./music | | ytdl mp4 <url\|query> | ytdl mp4 https://youtu.be/dQw4w9WgXcQ -q 720 · -q all | | ytdl search <query> | ytdl search believer -n 5 | | ytdl info <url\|query> | ytdl info https://youtu.be/dQw4w9WgXcQ | | ytdl playlist <url\|id> | ytdl playlist "https://youtube.com/playlist?list=PL…" --all |

Flags: -q/--quality · -n/--limit · -d/--dir · -s/--save · --all · --json · -v · -h. Output is JSON, so it pipes straight into jq.

🍳 Recipes

import { getPlaylist, ytmp3, slugify } from 'ytdl-lite';

const pl = await getPlaylist(process.argv[2], { all: true });
const dir = `./${slugify(pl.title)}`;

for (const v of pl.items) {
  try {
    const r = await ytmp3(v.url, 'best', { save: true, dir });
    console.log('✔', r.file);
  } catch (e) {
    console.error('✖', v.title, e.code);
  }
}
import express from 'express';
import { ytmp3, search, getInfo } from 'ytdl-lite';

const app = express();
const wrap = fn => (req, res) => fn(req).then(r => res.json(r))
  .catch(e => res.status(400).json({ error: e.code, message: e.message }));

app.get('/mp3',    wrap(r => ytmp3(r.query.q)));
app.get('/search', wrap(r => search(r.query.q, { limit: 10 })));
app.get('/info',   wrap(r => getInfo(r.query.q)));

app.listen(3000);
const [first, second] = await search('lofi hip hop', { limit: 2 });
const short = (await search('lofi', { limit: 10 })).filter(v => v.seconds < 300);
const mp3 = await ytmp3(short[0].url);
await ytmp4(URL, '720', {
  save: true,
  onProgress: ({ stage, percent }) =>
    process.stdout.write(`\r${stage} ${percent ?? '…'}%   `)
});

🟦 TypeScript

Types ship with the package — no @types needed.

import { ytmp4, getInfo, type VideoInfo, type DownloadResult } from 'ytdl-lite';

const info: VideoInfo = await getInfo(url);
const file: DownloadResult = await ytmp4(url, '720', { save: true });

❓ FAQ

🗺️ Roadmap

  • [x] ESM + CJS + TypeScript
  • [x] Search with multi-provider fallback
  • [x] Full metadata & playlists
  • [ ] Playlist batch download helper
  • [ ] Subtitle / caption listing
  • [ ] Channel & trending feeds

🤝 Contributing

Issues and PRs are welcome.

git clone https://github.com/dnuzi/ytdl-lite && cd ytdl-lite
npm test          # offline unit tests
npm run test:live # hits the real services

⚠️ Disclaimer

This project is for personal and educational use. Respect copyright and YouTube's Terms of Service. You are responsible for what you download.

MIT © DanuZz · Made with ❤️ in Sri Lanka

⭐ If this helped you, star the repo!