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-fileVerified import paths — ran on the pinned version, not inferred.
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.
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()))`.
Before calling `download`, use `fs.mkdirSync(options.directory, { recursive: true })` or `fs.promises.mkdir` to create the full directory path.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).
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.
Use CommonJS `require` syntax: `const download = require('download-file')`.Ensure the directory exists before initiating the download. Use `fs.mkdirSync(options.directory, { recursive: true });` or `fs.promises.mkdir(options.directory, { recursive: true });`.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).
No dependency data recorded yet.