A Nodejs module for downloading image to disk from a given URL
A Node module for downloading image to disk from a given URL




``sh`
npm install --save image-downloader
- url (required) - the image URL to download
- dest (required) - the image destination. Can be a directory or a
filename. If a directory is given, ID will automatically extract the image
filename from options.url (see usage bellow)options.url
- extractFilename - boolean indicating whether the image filename will be
automatically extracted from or not. Set to false to haveoptions.dest
without a file extension for example. (default: true){}
- headers - HTTP headers (default: )21
- timeout - milliseconds before a request times out
- maxRedirects - the maximum number of allowed redirects; if exceeded, an
error will be emitted. (default: )
For advanced options, see Node.js http.request()'s options documentation
Download to a directory and save with the original filename
`js
const download = require('image-downloader');
const options = {
url: 'http://someurl.com/image.jpg',
dest: '/path/to/dest', // will be saved to /path/to/dest/image.jpg
};
download.image(options)
.then(({ filename }) => {
console.log('Saved to', filename); // saved to /path/to/dest/image.jpg
})
.catch((err) => console.error(err));
`
Download to a directory and save with an another filename
`js
const download = require('image-downloader');
options = {
url: 'http://someurl.com/image2.jpg',
dest: '/path/to/dest/photo.jpg', // will be saved to /path/to/dest/photo.jpg
};
download.image(options)
.then(({ filename }) => {
console.log('Saved to', filename); // saved to /path/to/dest/photo.jpg
})
.catch((err) => console.error(err));
`
Download with another filename without extension
`js
const download = require('image-downloader');
options = {
url: 'http://someurl.com/image3.jpg',
dest: '/path/to/dest/photo', // will be saved to /path/to/dest/photo
extractFilename: false,
};
download.image(options)
.then(({ filename }) => {
console.log('Saved to', filename), // saved to /path/to/dest/photo
})
.catch((err) => console.error(err));
`
1. Install Nix Package Manager
2. Install direnv with your OS package manager
3. Hook it direnv into your shell
4. At the top-level of your project run:
`sh`
direnv allow
> The next time your launch your terminal and enter the top-level of your
> project, direnv` will check for changes.
Please follow CONTRIBUTING.md.
Under the MIT license. See LICENSE file for more details.