Socket
Socket
Sign inDemoInstall

nodejs-file-downloader

Package Overview
Dependencies
4
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

nodejs-file-downloader


Version published
Maintainers
1
Created

Readme

Source

nodejs-file-downloader is a simple utility for downloading files. It hides the complexity of dealing with streams, paths and duplicate file names.

Installation

$ npm install nodejs-file-downloader

Table of Contents

  • Examples

Examples

Basic

Download a large file with default configuration

const Downloader = require('nodejs-file-downloader');

(async () => {//Wrapping the code with an async function, just for the sake of example.

    const downloader = new Downloader({     
      url: 'http://212.183.159.230/200MB.zip',//If the file name already exists, a new file with the name 200MB1.zip is created.     
      directory: "./downloads",//This folder will be created, if it doesn't exist.               
    })
    
    await downloader.download();//Downloader.download() returns a promise.

    console.log('All done');

})();    

 

Get the progress of a download
const Downloader = require('nodejs-file-downloader');

(async () => {

   const downloader = new Downloader({     
      url: 'http://212.183.159.230/200MB.zip',     
      directory: "./downloads/2020/May",//Sub directories will also be automatically created if they do not exist.           
    })

    downloader.on('progress',(percentage)=>{//Downloader is an event emitter. You can register a "progress" event.
        console.log('% ',percentage)
    })
    
    await downloader.download();   

})();    

 

Custom file name

nodejs-file-downloader "deduces" the file name, from the URL or the response headers. If you want to overwrite it, supply a config.fileName property.


  const downloader = new Downloader({     
      url: 'http://212.183.159.230/200MB.zip',     
      directory: "./downloads/2020/May", 
      fileName:'somename.zip'//This will be the file name.        
  }) 

 

Overwrite existing files

By default, nodejs-file-downloader uses config.cloneFiles = true, which means that files with an existing name, will have a number appended to them.


  const downloader = new Downloader({     
      url: 'http://212.183.159.230/200MB.zip',     
      directory: "./",  
      cloneFiles:false//This will cause the downloader to re-write an existing file.   
  }) 

 

Keywords

FAQs

Last updated on 27 Aug 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc