2.0.5 • Published 6 years ago
easy-downloader v2.0.5
Easy Download
Download file from remote URL easily.
Installation
$ npm install easy-downloaderUsage
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.
API
easyDownload(url, destination, [options]);Parameters
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 totrueif you want to send the request body withapplication/jsoncontent 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 theheadersoption.
Related
- send-request: Lightweight HTTP client for Node.