I need to create a function in javascript where I can execute curl command:
curl -v -X POST -k -u testUser -d login=testUser2 -d password=123456
when i run above command in terminal it will prompt me the password, where I have the to enter the password and then I can login into the database.
I am new to Javascript so I don't know how to do that.
I read some article related to exec
and child process
command in Javascript but I didn't find any example that will show how I can implement said behavior. I am adding below the sample that I found on internet:
const { exec } = require('child_process');
export const executeCommand = (cmd, successCallback, errorCallback) => {
exec(cmd, (error, stdout, stderr) => {
if (error) {
// console.log(`error: ${error.message}`);
if (errorCallback) {
errorCallback(error.message);
}
return;
}
if (stderr) {
//console.log(`stderr: ${stderr}`);
if (errorCallback) {
errorCallback(stderr);
}
return;
}
//console.log(`stdout: ${stdout}`);
if (successCallback) {
successCallback(stdout);
}
});
};