What is the process for creating an input configuration file for the function?

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.
        ]
   }

Answer №1

function handleOnClick(sourceDir, targetDir){ // defining function to handle onClick event with 2 parameters
    exec('rsync -avz -e "ssh -o StrictHostKeyChecking=no -o\ UserKnownHostsFile = /dev/null" --progress' + sourceDir + targetDir, function(error,stdout,stderr){
        console.log('stdout:',stdout)
    })      
}

// Loading configuration settings
var configuration = require('config.js');

// Looping through all source directories in the configuration
for(var i=0;i<configuration.src.length;i++){
    handleOnClick(configuration.src[i].src_dir, configuration.src[i].to_dir)
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using Flask to trigger a Python function that requires input parameters when a button is clicked

I am working on a Flask web application that includes a download button. Instead of triggering a JavaScript function, I want the button to execute a Python method. This Python method should take the recently modified HTML code from the webpage as input. H ...

A guide on selecting the best UI container based on API data in React using TypeScript

I have been developing a control panel that showcases various videos and posts sourced from an API. One div displays video posts with thumbnails and text, while another shows text-based posts. Below is the code for both: <div className=""> &l ...

Automatically preselect the checkbox inputs with the API and update their status when they are interacted with

Hello fellow developer, I trust you are doing well. I am looking to have the checkboxes automatically checked based on data from the API and update their status when interacted with. I've tried different approaches but haven't found the right sol ...

Build a flexible Yup validation schema using JSON data

I am currently utilizing the power of Yup in conjunction with Formik within my react form setup. The fields within the form are dynamic, meaning their validations need to be dynamic as well. export const formData = [ { id: "name", label: "Full n ...

Modify HTML content according to the response received from the backend

I am trying to dynamically update the text content of an HTML tag based on a response from the backend. My application is running on a Django server where I have a timer in the backend measuring the processing time. I need to send this processing time to t ...

What causes json.parse to malfunction? and how can you resolve the issue

My server sends data to my JavaScript code in the format below. {"triggers": [{"message_type": "sms","recipients": "[\"+91xxxxxxxxx\",\"+91xxxxxxxxx\"]", "message": "This is a test"}]} To parse this JSON string, my code executes the f ...

Troubles arising from Maya 2017 export to ThreeJS

I'm facing an issue with exporting from Maya to Three.js Using Maya 2017 on a Mac and recently downloaded ThreeJS from the site. Initially, I had no problems with the .min version (seems to be Revision 57). I was utilizing mesh = new THREE.Mesh(geom ...

Error encountered during Yarn installation process: The tunneling socket was unable to be established due to a connection refusal on localhost at port 80

I have a Next.js app that needs to be built on our company servers before deployment. We use a proxy, and I've configured yarn to use the proxy as well. yarn config set proxy http://xx.xxx.xx:xxxx yarn config set httpsProxy http://xx.xxx.xx:xxxx yarn ...

Combining multiple arrays into a single array using functions and pointers in the C programming language

I have attempted using functions and arrays to solve this problem, but I have encountered difficulties and now want to tackle it using pointers. However, I am facing issues with passing and accessing array values using pointers. Below is the code snippet ...

Getting the error message "t is not a function. (In 't(i,c)', 't' is an instance of Object)" while attempting to switch from using createStore to configureStore with React Redux Toolkit

I am attempting to switch from react-redux to its alternative react-redux toolkit but I kept encountering this issue t is not a function. (In 't(i,c)', 't' is an instance of Object) and I am unsure of its meaning. Here is the c ...

I'm experiencing difficulty accessing the correct identification number for my questions on the website

Hi, I'm currently developing a website using Meteor where users can post questions and receive answers. I want to implement a feature that allows users to delete their own questions. When I try to directly pull the ID of the question and delete it, it ...

Encountering a 404 error with Angular 6 routing after refreshing the page when using an Nginx proxy

I currently have my angular application running within a docker container, exposed on port 83. Additionally, I have a separate spring-boot rest app running inside another docker container, exposed on port 8083. On the host server, there is an Nginx server ...

In JavaScript, when you update the property of a nested object within an array, the changes will also be applied to the same property for

Encountered an interesting issue in my code where updating a single property of a nested object within an array of objects results in all similar objects having the same property updated. Snippet of the Code: let financials = { qr: { controlData: [ ...

Incrementing pages, starting with page1.html and continuing to page2.html, page3.html, and beyond, for use with the window

How should I handle this situation? My goal is to automatically navigate to the next page once all necessary functions have been completed. For instance, after all functions on page1.html are finished, it will trigger a function called next_page(). The n ...

How to save array data to a text file using node.js

I have an array containing values that I want to write to a text file using the following code. while(filedataarr.length>0) { firstelement = filedataarr.shift(); //console.log(firstelement); fs.appendFile("D:\\Temp& ...

Ways to create interactive multiple dropdown menu using vue-multiselect

I'm not sure if it's possible to achieve what I want with Vue for a specific component by changing its data and automatically loading it. Below is my expectation (tried in jQuery) var data = {country:{type:'dropdown',values:[' ...

What is the best method for clearing all session cookies in my React application?

Currently, I am working on a project using React. I am trying to find a method to automatically logout the user by deleting all of the session cookies in my React application. However, I have not been able to come up with a solution yet. Is there a way to ...

Ways to transfer data between Angular controller and jQuery

Looking for some guidance on how to toggle between two HTML divs based on user input validation using an Angular controller and jQuery animations. Each div contains input fields that need to be validated before moving on to the next stage. Here is a simpli ...

Ensure that only one menu with a specific class is open at any given time

My goal is to ensure that both menus cannot be open simultaneously. The desired behavior is as follows: When one menu is already open and you click on another, the first one should automatically close. For a better understanding of what I am trying to achi ...

Is there a way to determine the duration that a click was held down for?

When triggering an onClick event, I want to determine whether it was a single click or if the mouse button was held down for some time before releasing. This way, I can call the myTest() function within onClick="myTest()", which will log "mouse was click ...