{"id":10760,"library":"download-file","title":"download-file","description":"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.","status":"abandoned","version":"0.1.5","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","download","file","url","get","http","https"],"install":[{"cmd":"npm install download-file","lang":"bash","label":"npm"},{"cmd":"yarn add download-file","lang":"bash","label":"yarn"},{"cmd":"pnpm add download-file","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package is CommonJS-only and does not officially support ES Modules imports. Use `require`.","wrong":"import download from 'download-file'","symbol":"download","correct":"const download = require('download-file')"},{"note":"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.","wrong":"import { download } from 'download-file'","symbol":"download (named)","correct":"const { download } = require('download-file')"}],"quickstart":{"code":"const download = require('download-file');\nconst fs = require('fs');\nconst path = require('path');\n\nconst imageUrl = \"https://picsum.photos/id/237/800/600\"; // A reliable public image URL\nconst videoUrl = \"https://www.w3schools.com/html/mov_bbb.mp4\"; // A reliable public video URL\n\n// --- Example 1: Image download ---\nconst imageOptions = {\n    directory: \"./downloads/images/\",\n    filename: \"random_image.jpg\"\n};\n\n// Ensure the target directory exists before attempting to download\nfs.mkdirSync(imageOptions.directory, { recursive: true });\n\nconsole.log(`Attempting to download image from ${imageUrl} to ${path.join(imageOptions.directory, imageOptions.filename)}`);\ndownload(imageUrl, imageOptions, function(err){\n    if (err) {\n        console.error(\"Image download failed:\", err);\n        return;\n    }\n    console.log(\"Image 'random_image.jpg' downloaded successfully!\");\n});\n\n// --- Example 2: Video download with a custom timeout ---\nconst videoOptions = {\n    directory: \"./downloads/videos/\",\n    filename: \"big_buck_bunny.mp4\",\n    timeout: 30000 // 30 seconds, increased for potentially larger files\n};\n\nfs.mkdirSync(videoOptions.directory, { recursive: true });\n\nconsole.log(`Attempting to download video from ${videoUrl} to ${path.join(videoOptions.directory, videoOptions.filename)}`);\ndownload(videoUrl, videoOptions, function(err){\n    if (err) {\n        console.error(\"Video download failed:\", err);\n        return;\n    }\n    console.log(\"Video 'big_buck_bunny.mp4' downloaded successfully!\");\n});","lang":"javascript","description":"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."},"warnings":[{"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()))`.","message":"The 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.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Before calling `download`, use `fs.mkdirSync(options.directory, { recursive: true })` or `fs.promises.mkdir` to create the full directory path.","message":"The 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.","severity":"gotcha","affected_versions":">=0.1.0"},{"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).","message":"This 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.","severity":"gotcha","affected_versions":"<=0.1.5"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Use CommonJS `require` syntax: `const download = require('download-file')`.","cause":"Attempting to use ES Modules `import` syntax (`import download from 'download-file'`) in a context where the package is only published as CommonJS.","error":"Error: Cannot find module 'download-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 });`.","cause":"The target directory specified in the `options.directory` did not exist when the download attempted to write the file.","error":"Error: ENOENT: no such file or directory, open './path/to/non-existent/directory/file.jpg'"},{"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).","cause":"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.","error":"Error: connect ETIMEDOUT"}],"ecosystem":"npm"}