Within the file rsync.js, there exists a function:
rsync.js
var onClick = function(){
exec('rsync -avz -e "ssh -o StrictHostKeyChecking=no -o\ UserKnownHostsFile = /dev/null" --progress' + src_dir + to_dir,\
function(error,stdout,stderr){
console.log('stdout:',stdout)} )
}
Suppose I wish to execute the above code for three different directories already on the system. In this scenario, I simply need to modify the src_dir
and to_dir
to provide inputs to the onClick
function.
To achieve this, I plan to create an input configuration file in JSON format. By requiring this in the rsync.js file, I can provide only the src_dir
and to_dir
inputs to the function and have it work for all three directories.
Question1: How can I iterate through the array list present in the config.js file?
Question2: How do I provide input to the onClick
function?
For example:
var onClick = function(src_dir= "", to_dir= ""){}
Attempt 1: I have created an array list for both source and destination directories. However, I am currently struggling to iterate through it.
config.js
module.exports = {
src: [
{ src_dir: '/path/to/source/dir/', to_dir : '/path/to/remote/dir'},
//additional array elements.
]
}