Node Downloader Helper

2.1.11 · active · verified Tue Apr 21

node-downloader-helper is a robust, zero-dependency file downloader for Node.js, supporting HTTP and HTTPS protocols. It's built for environments like vanilla Node.js, Electron, and NW.js, providing features essential for reliable file transfers. Key functionalities include pause and resume capabilities, automatic retry mechanisms for failed downloads, handling of HTTP redirects, and the option to pipe downloaded content for on-the-fly processing. Currently stable at version 2.1.11, the library demonstrates an active release cadence, with frequent patch updates addressing bugs, performance optimizations, and feature enhancements. Its primary differentiators are its complete independence from third-party packages, minimizing its attack surface and simplifying its dependency tree, along with comprehensive error management and detailed progress statistics.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize `DownloaderHelper`, configure basic options like retries and a custom filename, and set up event listeners for monitoring download progress, completion, and errors. It also ensures the download directory exists before starting.

import { DownloaderHelper } from 'node-downloader-helper';
import path from 'path';
import fs from 'fs';

const downloadUrl = 'https://proof.ovh.net/files/1Gb.dat'; // Example URL for a large file
const destinationFolder = path.join(__dirname, 'downloads');

// Ensure the destination folder exists
if (!fs.existsSync(destinationFolder)) {
  fs.mkdirSync(destinationFolder, { recursive: true });
}

const dl = new DownloaderHelper(downloadUrl, destinationFolder, {
  fileName: 'test-file.dat',
  retry: { maxRetries: 3, delay: 1000 }, // Retry 3 times with 1-second delay
  resumeOnIncomplete: true,
  maxRedirects: 5
});

dl.on('start', () => console.log(`Starting download for ${downloadUrl} to ${destinationFolder}`));
dl.on('progress', (stats) => {
  const progress = stats.progress.toFixed(2);
  const speed = (stats.speed / 1024 / 1024).toFixed(2); // MB/s
  console.log(`Progress: ${progress}% - Speed: ${speed} MB/s - Downloaded: ${(stats.downloaded / 1024 / 1024).toFixed(2)} MB`);
});
dl.on('end', () => console.log('Download Completed successfully!'));
dl.on('error', (err) => console.error('Download Failed:', err.message));
dl.on('timeout', () => console.error('Download Timed out!'));
dl.on('skip', (info) => console.log(`Download skipped: ${info.message}`));

dl.start().catch(err => {
  console.error('Failed to initiate download:', err.message);
});

view raw JSON →