Easy Downloader

A promised based library for downloading file.
Install
$ npm install easy-downloader
Usage
const EasyDownloader = require('easy-downloader');
EasyDownloader.download({ uri: 'httpbin.org/image/png', destination: 'test.png' })
.then(destination => console.log(`File is downloaded to: ${destination}`))
.catch(e => console.error(e.message));
API
EasyDownloader.download({
uri, destination,
[method, encoding, data, formData, headers, auth]
});
Required Parameters:
uri
(String
): The URI of the file that you want to download.destination
(String
): The path where your downloaded file will be written.
Optional Parameters:
method
(String
): The HTTP request method, default to GET
.encoding
(String
): Character encoding that will be used to interpret the response from the target URI. Check the Buffer documentation for more information.data
(Object
): Request body that needs to be sent as JSON formatted data.formData
(Object
): Request body that needs to be sent in x-www-form-urlencoded
format.headers
(Object
): Request headers that need to sent.auth
(Object
): HTTP basic authentication credentials, you have to pass the username
and password
properties like so: { username: 'john', password: 'secret' }
.
Note that data
and formData
are only applicable for request methods 'PUT', 'POST', and 'PATCH'. Also the Content-Type
and Content-Length
headers will be automatically provided for you.
Example
EasyDownloader.download({
uri: 'http://example.com/download',
destination: 'test.txt',
method: 'POST',
encoding: 'utf8',
formData: {
foo: 'bar'
},
headers: {
'X-Powered-By': 'Easy Downloader'
},
auth: {
username: 'john',
password: 'secret'
}
})
.then(destination => console.log(`File is downloaded to: ${destination}`))
.catch(e => console.error(e.message));
License
MIT © Risan Bagja Pradana