download
Download and extract files effortlessly in Node.js.
Getting started
Install with npm: npm install download
Examples
If you're fetching an archive you can set extract: true
in options and
it'll extract it for you.
var download = require('download');
// download and extract `foo.tar.gz` into `bar/`
download('foo.tar.gz', 'bar', { extract: true });
// download and save `foo.exe` into `bar/foo.exe` with mode `0755`
download('foo.exe', 'bar', { mode: '0755' });
// download and save an array of files in `bar/`
var files = ['foo.jpg', 'bar.jpg', 'cat.jpg'];
download(files, 'bar');
API
download(url, dest, opts)
Download a file or an array of files to a given destination. Returns an EventEmitter
with three possible events — response
, data
and error
.
Options
extract
— If set totrue
, try extracting the file using decompressmode
— Set mode on the downloaded filesstrip
— Equivalent to--strip-components
for tar
You can also define options accepted by the request module.