Download videos from YouTube with Node.js

Use YouTube Video Downloader to download videos from YouTube with Node.js. Want to add YouTube downloads to your own Node.js project? Just pass your video URLs to the Actor with the Apify JavaScript client and get MP4 files saved straight to your cloud storage.

Easy setup to get videos programmatically in Node.js

Sign up on Apify01

Create a free Apify account (no credit card needed) and find YouTube Video Downloader in Apify Store.

Sign up for free
Initialize the API using your token02

Once you have an account, add your API token. You’ll find it on the Integrations page in Apify Console.

Get your token in Console
Define input and copy it in JSON03

Open YouTube Video Downloader in Apify Console, add the YouTube video URLs you want to download, and pick your format and quality. Then copy the input as JSON from the Input tab and paste it into your code.

Integrate Apify into your codebase04

Call YouTube Video Downloader from your Node.js project with the Apify JavaScript client or the API endpoints. Run the sample code below and your videos land in Apify Storage, or in your own S3, Google Cloud Storage, or Azure bucket ↓.

Monitor your YouTube Video Downloader runs05

Open your Apify Console dashboard and watch YouTube Video Downloader runs execute in real time. You can also download the run logs, set up schedules so runs repeat on their own, and use webhooks to trigger the next step in your pipeline as soon as a download finishes.

Go to dashboard

Get your Node.js project up and running

Start your Node.js project by executing this code snippet in your go-to environment.

1import { ApifyClient } from 'apify-client';
2
3// Initialize the ApifyClient with your Apify API token
4// Replace the '<YOUR_API_TOKEN>' with your token
5const client = new ApifyClient({
6 token: '<YOUR_API_TOKEN>',
7});
8
9// Prepare Actor input
10const input = {
11 "videos": [
12 {
13 "url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
14 }
15 ]
16};
17
18// Run the Actor and wait for it to finish
19const run = await client.actor("streamers/youtube-video-downloader").call(input);
20
21// Fetch and print Actor results from the run's dataset (if any)
22console.log('Results from dataset');
23console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
24const { items } = await client.dataset(run.defaultDatasetId).listItems();
25items.forEach((item) => {
26 console.dir(item);
27});
28
29// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs
Free $5 usage every month

Enjoy $5 of free platform usage every month to explore and kickstart your projects.

No credit card required

Get started on Apify instantly without the hassle of entering your credit card information.

Supportive community on Discord

Join our Discord community to ask questions, share ideas, and connect with developers.

Frequently asked questions

You give YouTube Video Downloader a list of YouTube video URLs and pick a format and quality. It fetches each video, converts it if you asked for a different format, and saves the file to Apify Storage or your own cloud storage bucket. You can start all of that from Node.js with the Apify API client.

Yes. Every Actor on Apify has a REST API, and the Apify JavaScript client wraps it. Pass your video URLs as input, start the run, then read the output from the run's dataset or key-value store. The sample code above is a working starting point.

MP4 is the usual choice, and AVI, MKV, MOV, and WebM are available too, with quality settings from 144p up to 2160p. If you only need the audio, pick MP3, AAC, FLAC, M4A, OGG, OPUS, or WAV.

Actors are serverless cloud programs that run on the Apify platform and do computing jobs. They’re called Actors because, like human actors, they perform actions based on a script. They can perform anything from simple actions (such as filling out a web form or sending an email) to complex operations (such as crawling an entire website or removing duplicates from a large dataset). Actor runs can be as short or as long as necessary. They could last seconds, hours, or even run infinitely.

Ready to get started?

Create your free Apify account to download YouTube videos now.