Registry / http-networking / download-file

download-file

JSON →
library0.2jsnpmunverified

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.

npm install download-file
INSTALL
IMPORT
SIG · DOWNLOAD-FILE
D
download-file
http-networkingjavascriptv0.2
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

download
✓ const download = require('download-file')
✗ import download from 'download-file'
The package is CommonJS-only and does not officially support ES Modules imports. Use `require`.
download (named)
✓ const { download } = require('download-file')
✗ import { download } from 'download-file'
Although it exports a single function, it is exported as the module.exports default, not as a named export. The `{ download }` destructuring pattern will not work correctly.

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!"); });
Debug
Known issues
gotchaThe package uses a callback-based API exclusively. It does not provide Promise or async/await support, which is common in modern Node.js development. This can lead to 'callback hell' for complex sequences of downloads.
fix
Wrap the `download` function in a Promise manually if modern async/await patterns are desired, e.g., `new Promise((resolve, reject) => download(url, options, err => err ? reject(err) : resolve()))`.
affects: >=0.1.0
gotchaThe package does not automatically create the specified `directory` path. If the target directory does not exist, the download will fail with an `ENOENT` error. Developers must manually ensure the directory structure is in place.
fix
Before calling `download`, use `fs.mkdirSync(options.directory, { recursive: true })` or `fs.promises.mkdir` to create the full directory path.
affects: >=0.1.0
gotchaThis package is at a very low version (0.1.5) and appears to be unmaintained. There haven't been updates for a significant period, which could mean it lacks bug fixes, security patches, or compatibility updates for newer Node.js versions or HTTP standards.
fix
For new projects or critical applications, consider more actively maintained alternatives like `node-fetch`, `axios`, or `got` which offer modern APIs, better error handling, and more features (e.g., progress tracking, retries, cancellation).
affects: <=0.1.5
gotchaThe package provides basic timeout functionality but lacks advanced features like progress events, stream-based processing for large files, automatic retries on network failures, or integration with `AbortController` for cancellation.
fix
For these advanced requirements, consider using more robust HTTP clients or implementing these features manually around the basic download functionality, or again, opting for a more feature-rich library.
affects: >=0.1.0
Errors
Common errors & fixes
Error: Cannot find module 'download-file'
Attempting to use ES Modules `import` syntax (`import download from 'download-file'`) in a context where the package is only published as CommonJS.
fix
Use CommonJS `require` syntax: `const download = require('download-file')`.
Error: ENOENT: no such file or directory, open './path/to/non-existent/directory/file.jpg'
The target directory specified in the `options.directory` did not exist when the download attempted to write the file.
fix
Ensure the directory exists before initiating the download. Use `fs.mkdirSync(options.directory, { recursive: true });` or `fs.promises.mkdir(options.directory, { recursive: true });`.
Error: connect ETIMEDOUT
The network connection timed out, either due to a slow server, network issues, or the `timeout` option being set too low for a large file or remote server response.
fix
Increase the `timeout` option in milliseconds (e.g., `timeout: 60000` for 60 seconds) or check network connectivity and the availability of the remote server. The default timeout is 20000ms (20 seconds).
Upgrade
Version history
0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
10
OpenAI (training)
1
Resources
download-file — npm install download-file · libregistry