I am looking for running a function in JS when a button is clicked in the interface, I expect that it should execute terminal commands, this is the job of the function.
The first thing which came into my mind is that to use the OS module in Python so that I can use os.system() to run terminal commands, I found some videos on YouTube but most of them do guide you how to do it but not from client-side.
It would be really appreciated if you can explain me what's client-side, because I asked for help on Discord but people keep talking about it, I just need a simple understandable explanation/summary/conclusion
So, when I found no resource to run a Python script from JS, I though about running the terminal commands directly from JS, but still didn't found any resource which can help
So, you would like to understand more? Here is my case:
I am making a web app which is a code obfuscator, and to obfuscate code I want to use terminal commands, those commands work without problems, so I want to run those commands from JS.
The app will be hosted on a Linux Server (Linode) provided by Linode, it's Ubuntu LTS
Note: This project is a web app, HTML/CSS/JS and extra
Thanks for your help! Feel free if you have any doubts ask me in the commments
Regarding your first question.
Client-side (rendering) refers to everything in a web application that is displayed or takes place on the client (end-user device). This includes what the user sees, such as text, images, and the rest of the UI, along with any actions an application performs within the user's browser.
Because of these reasons and since you can't run anything else but HTML, CSS, and pure JavaScript on the client-side, you can also understand why you can not execute bash commands on the client-side; for that, you'll have to create a server-side application that will catch the request from the client-side, execute/complete the request, and return the result to the client.
There is a nice article about client-side working with the back-end which you can read here https://dev.to/gbudjeakp/how-to-connect-your-client-side-to-your-server-side-using-node-and-express-2i71
From there and once you'll have the server-side client running you'll be able to use packages like "child_process" which will help you execute bash commands for example and a lot more
Simple example running ls using child_process
const { exec } = require("child_process");
exec("ls -la", (err, stdout, stderr) => {
if (err) {
console.log(`error: ${err.message}`);
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
return;
}
console.log(`stdout: ${stdout}`);
});