easy-downloader

Download file from remote URL easily.

Usage no npm install needed!

<script type="module">
  import easyDownloader from 'https://cdn.skypack.dev/easy-downloader';
</script>

README

Easy Download

Build Status Test Covarage Latest Version

Download file from remote URL easily.

Installation

$ npm install easy-downloader

Usage

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 (optional Object): The HTTP request configuration
    • method (String): The HTTP method to use, default to GET.
    • 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 of FormData.
    • json (Boolean): Set to true if you want to send the request body with application/json content type. Default to false, which means that the request body will be sent as application/x-www-form-urlencoded. Note that you can still override the content type using the headers option.

Related

License

MIT © Risan Bagja Pradana