Download file from remote URL easily.
$ npm install easy-downloader
const easyDownload = require("easy-downloader");
(async () => {
try {
await easyDownload("https://httpbin.org/image/jpeg", "foo/bar/baz.jpg");
} catch (error) {
console.error(error.message);
}
})();
The foo/bar
directory will be created automatically if it does not exist.
easyDownload(url, destination, [options]);
url
(String
): The file URL to download.destination
(String
): The path to save the downloaded file.options
(optionalObject
): The HTTP request configurationmethod
(String
): The HTTP method to use, default toGET
.headers
(Object
): The request headers to send.auth.username
(String
): The username for HTTP basic auth.auth.password
(String
): The password for HTTP basic auth.body
(Object|FormData
): The request body to send. It can be a plain JavaScript object or an instance ofFormData
.json
(Boolean
): Set totrue
if you want to send the request body withapplication/json
content type. Default tofalse
, which means that the request body will be sent asapplication/x-www-form-urlencoded
. Note that you can still override the content type using theheaders
option.
- send-request: Lightweight HTTP client for Node.