#!/usr/local/bin/node
"use strict"; 
const DS = '/';
const DOWNLOAD_DIR = '/home/pi/app/arch/';
const moddir      = '/usr/local/lib/node_modules/';
const exec = require("child_process").exec;
const spawn = require("child_process").spawn;

	//let http = require('http');
	let path = require('path');
	let fs = require('fs');
	let url = require('url');


// Function to download file using wget
var download_file_wget = function(file_url) {
    // extract the file name
    var file_name = url.parse(file_url).pathname.split('/').pop();
    // compose the wget command
    var rm = 'rm -f ' + DOWNLOAD_DIR + file_name;
    var wget = 'wget -P ' + DOWNLOAD_DIR + ' ' + file_url;
	//console.log(9,rm)
    // excute wget using child_process' exec function
		exec(rm, function(err, stdout, stderr) {
			//console.log(('---',err, stdout, stderr))
			var child = exec(wget, function(err, stdout, stderr) {
				if (err) throw err;
				else console.log(file_name + ' downloaded to ' + DOWNLOAD_DIR);
			});
		});
};



// Function to download file using curl
var download_file_curl = function(file_url) {
    // extract the file name
    var file_name = url.parse(file_url).pathname.split('/').pop();
    // create an instance of writable stream
    var file = fs.createWriteStream(DOWNLOAD_DIR + file_name);
    // execute curl using child_process' spawn function
    var curl = spawn('curl', [file_url]);
    // add a 'data' event listener for the spawn instance
    curl.stdout.on('data', function(data) { file.write(data); });
    // add an 'end' event listener to close the writeable stream
    curl.stdout.on('end', function(data) {
        file.end();
        console.log(file_name + ' downloaded to ' + DOWNLOAD_DIR);
    });
    // when the spawn child process exits, check if there were any errors and close the writeable stream
    curl.on('exit', function(code) {
        if (code != 0) {
            console.log('Failed: ' + code);
        }
    });
};



let serverURLs = [
'https://raw.githubusercontent.com/ZnakZorro/radioRADIO/master/radio.json',
'https://raw.githubusercontent.com/ZnakZorro/radioRADIO/master/rss.js',
'https://raw.githubusercontent.com/ZnakZorro/radioRADIO/master/server.js',
'https://raw.githubusercontent.com/ZnakZorro/radioRADIO/master/index.js',
'https://raw.githubusercontent.com/ZnakZorro/radioRADIO/master/index.html',
'https://raw.githubusercontent.com/ZnakZorro/radioRADIO/master/node/sos.js',
'https://raw.githubusercontent.com/ZnakZorro/radioRADIO/master/node/cam/one.js'
];

serverURLs.forEach(function(serverURL,i){
		console.log(i,'---',serverURL);
		download_file_wget(serverURL);
	});
//download_file_curl(serverURL);


@@ -237,12 +237,12 @@
 ;%0A%0A%09
-//le
+cons
 t ht
@@ -264,18 +264,20 @@
 ttp');%0A%09
-le
+cons
 t path =
@@ -295,18 +295,20 @@
 ath');%0A%09
-le
+cons
 t fs = r
@@ -322,18 +322,20 @@
 'fs');%0A%09
-le
+cons
 t url = 
@@ -1956,16 +1956,1036 @@
 %7D);%0A%7D;%0A%0A
+%0A/*%0A%0A// dowload by http%0Avar hfile_url = 'https://www.wi.zut.edu.pl/templates/wizut/assets/images/logo/zut-logo-1.jpg';%0A%0A%0A// We will be downloading the files to a directory, so make sure it's there%0A// This step is not required if you have manually created the directory%0Avar mkdir = 'mkdir -p ' + DOWNLOAD_DIR;%0Avar child = exec(mkdir, function(err, stdout, stderr) %7B%0A    if (err) throw err;%0A    else download_file_httpget(hfile_url);%0A%7D);%0A%0A// Function to download file using HTTP.get%0Avar download_file_httpget = function(hfile_url) %7B%0Avar options = %7B%0A    host: url.parse(hfile_url).host,%0A    port: 80,%0A    path: url.parse(hfile_url).pathname%0A%7D;%0A%0Avar file_name = url.parse(hfile_url).pathname.split('/').pop();%0Avar file = fs.createWriteStream(DOWNLOAD_DIR + file_name);%0A%0Ahttp.get(options, function(res) %7B%0A    res.on('data', function(data) %7B%0A            file.write(data);%0A        %7D).on('end', function() %7B%0A            file.end();%0A            console.log(file_name + ' downloaded to ' + DOWNLOAD_DIR);%0A        %7D);%0A    %7D);%0A%7D;%0A*/
 %0A%0Alet se

Update download.js