download-file

0.1.5 · abandoned · verified Sun Apr 19

download-file is a minimalist Node.js utility for asynchronously downloading files from a given URL to a specified local directory. Currently at version 0.1.5, the package operates exclusively using a traditional Node.js callback-based API, lacking modern Promise or async/await support. Its release cadence appears to be very slow or halted, suggesting it is either in a long-term maintenance mode or effectively abandoned. The package provides a simple interface, requiring just a URL and an optional configuration object for the target directory and filename. It focuses solely on basic file transfer and local storage, without advanced features such as progress tracking, automatic retries, or robust error handling for network interruptions, file system issues beyond basic `ENOENT`, or `AbortController` integration. This simplicity positions it as a lightweight solution for very basic, fire-and-forget download tasks within a Node.js environment.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates downloading two different files (an image and a video) to specific local directories. It includes necessary directory creation using `fs.mkdirSync` and basic error handling, showcasing the package's callback-based API and timeout option.

const download = require('download-file');
const fs = require('fs');
const path = require('path');

const imageUrl = "https://picsum.photos/id/237/800/600"; // A reliable public image URL
const videoUrl = "https://www.w3schools.com/html/mov_bbb.mp4"; // A reliable public video URL

// --- Example 1: Image download ---
const imageOptions = {
    directory: "./downloads/images/",
    filename: "random_image.jpg"
};

// Ensure the target directory exists before attempting to download
fs.mkdirSync(imageOptions.directory, { recursive: true });

console.log(`Attempting to download image from ${imageUrl} to ${path.join(imageOptions.directory, imageOptions.filename)}`);
download(imageUrl, imageOptions, function(err){
    if (err) {
        console.error("Image download failed:", err);
        return;
    }
    console.log("Image 'random_image.jpg' downloaded successfully!");
});

// --- Example 2: Video download with a custom timeout ---
const videoOptions = {
    directory: "./downloads/videos/",
    filename: "big_buck_bunny.mp4",
    timeout: 30000 // 30 seconds, increased for potentially larger files
};

fs.mkdirSync(videoOptions.directory, { recursive: true });

console.log(`Attempting to download video from ${videoUrl} to ${path.join(videoOptions.directory, videoOptions.filename)}`);
download(videoUrl, videoOptions, function(err){
    if (err) {
        console.error("Video download failed:", err);
        return;
    }
    console.log("Video 'big_buck_bunny.mp4' downloaded successfully!");
});

view raw JSON →