Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

node js download file to folder

var http = require('http');
var fs = require('fs');

var download = function(url, dest, cb) {
  var file = fs.createWriteStream(dest);
  var request = http.get(url, function(response) {
    response.pipe(file);
    file.on('finish', function() {
      file.close(cb);  // close() is async, call cb after close completes.
    });
  }).on('error', function(err) { // Handle errors
    fs.unlink(dest); // Delete the file async. (But we don't check the result)
    if (cb) cb(err.message);
  });
};
Comment

PREVIOUS NEXT
Code Example
Javascript :: Array Foreach Loop 
Javascript :: jquery each response 
Javascript :: forjs check if key in json 
Javascript :: how to get on click id in event 
Javascript :: vuex state from another module 
Javascript :: find last element in array nodejs 
Javascript :: javascript next month from date 
Javascript :: set cookie and get cookie in javascript 
Javascript :: js get first element of array 
Javascript :: supertest multipart/form-data 
Javascript :: immediately invoked function expression async 
Javascript :: input type number maxlength in react 
Javascript :: or inside if javascript 
Javascript :: javascript template literals 
Javascript :: javascript initialize array 
Javascript :: how to merge 2 object array by the same key with lodash 
Javascript :: javascript hours minutes seconds 
Javascript :: binarycent login 
Javascript :: react native header 
Javascript :: js set iframe src 
Javascript :: object clone javascript 
Javascript :: round decimal js 
Javascript :: how to check input is selected or not 
Javascript :: Error R10 (Boot timeout) - Web process failed to bind to $PORT within 60 seconds of launch 
Javascript :: javascript max array 
Javascript :: mongoose virtual 
Javascript :: inc a value mongoose 
Javascript :: js how to find element using id 
Javascript :: javascript object array contains 
Javascript :: how to access dictionary keys in js 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =